1factory(App\User::class, 30)->create()->each(function($user) {
2
3 $entity = factory(App\Entity::class)->make();
4
5 $address = factory(App\Address::class)->create([
6 'entity_id' => $entity
7 ]);
8
9 $user->entities()->save($entity);
10});
1For Laravel version 7.* and less
2factory(App\User::class, 3)->make();
3
4Use create method to persist them to the database:
5factory(App\User::class, 3)->create();