public function First_name()
{
return $this->hasOne('App\FirstName', 'id', 'first_name');
}
When I attempt a database seed with that relationship, I get a segmentation fault. I considered that since the first_name int within the Users table will correspond with the id column on the first_names table, that it would work.
I've realised my relationships were wrong. User model should belong to first and last names models, and first and last names model have many users.
public function First_name()
{
return $this->belongsTo('App\FirstName', 'first_name');
}
public function users()
{
return $this->hasMany('App\User', 'first_name');
}
But still cannot see any way of incorporating this into a seed script.
factory(App\User::class, 20)->create()->each(function($user){
$user->password()->save(factory(App\Password::class)->make());
$user->First_name()->save(factory(App\FirstName::class)->make());
$user->Last_name()->save(factory(App\LastName::class)->make());
});
Please help!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community