I have a User model with custom attribute,
attribute name
that concatenate firstName
and lastName
:
class User extends Authenticatable
{
/**
* @var array
*/
protected $fillable = ['firstName', 'lastName'];
protected $appends = [
'name'
];
public function getNameAttribute(){
return $this->attributes['firstName'] . ' ' . $this->attributes['lastName'];
}
}
Also I have a many to many relation to Group
model.
The problem is, when I try to do seeding:
factory(App\Group::class, 30)
->create()
->each(function ($group) {
$group->users()->createMany(factory(App\User::class, 3)->make()->toArray());
});
I get exception:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'name' in 'field list'
My Factory:
$factory->define(User::class, function (Faker $faker) {
return [
'firstName' => $faker->firstName,
'lastName' => $faker->lastName,
];
});
When I comment name
attribute, it works fine.
Thanks.