Closed agence86 closed 9 years ago
Can you post a code example? Check that it's actually including the traits as required.
Your model has to extend the Eloquence model. If it's not doing that - you won't see those methods.
Do i have to include the trait in each Models?
User Model
<?php namespace App;
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract {
use Authenticatable, CanResetPassword;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['email', 'password'];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = ['password', 'remember_token'];
public function addresses()
{
return $this->belongsToMany('YetismailApi\Models\Moderator');
}
}
IN a controller
$user = new User();
var_dump($user->generateNewUuid());
throws undefined method generateNewUuid in Builder class
Thanks
No, just extending the Eloquence model is enough (which you're not doing).
so i need to use use Eloquence\Database\Model; insted of use Illuminate\Database\Eloquent\Model;
So i dont understand the bind effect in service provider. I would think it will include extended methods in the core Model class
Correct.
Right thank you i'll try this way.
Last question btw what is the effect of the bind in service provider so?
The reason for the service provider, is to re-bind the model to the Eloquence implementation. This is necessary for things like pivot tables and camel-casing, ensuring they also abide by the same rules :)
Without it, you end up with snake_case fields in pivot models, but camelCase everywhere else.
ho ok!
Thank you very much! Have a nice day
You too :)
Hi,
when i follow your readme.md, il loaded with composer, i included the service provider in app.php but when i create a new model object it doesn't execute the uuid generation. By the way the closure is loaded in the core laravel Model object but it doesn't affect this class...
Even when i try to call
$user= new User(); $user->generateNewUuid(); it throw undefined method in user (and it try to search the method in query builder)
any idea?
Thanks in advance
Cedric LE ROY