Skip to content

Instantly share code, notes, and snippets.

@flyingluscas
Last active October 28, 2016 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flyingluscas/e0a194be1bf668c9af515ef033e684b9 to your computer and use it in GitHub Desktop.
Save flyingluscas/e0a194be1bf668c9af515ef033e684b9 to your computer and use it in GitHub Desktop.
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