Support the ongoing development of Laravel.io →
posted 7 years ago
Database
Last updated 1 year ago.
0
    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.

0

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!

0

Sign in to participate in this thread!

Eventy

Your banner here too?

winers1290 winers1290 Joined 21 Jun 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.