Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Laravel - Example of relationships on seeders
use Illuminate\Database\Seeder;

class ClientTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        factory(App\Client::class, 10)->make()->each(function ($client) {
            $address = factory(App\Address::class)->create();
        
            $client->address()
                   ->associate($address)
                   ->save();
        });
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.