laravel factories relationships code example
Example: laravel factory relations data
factory(App\User::class, 30)->create()->each(function($user) {
$entity = factory(App\Entity::class)->make();
$address = factory(App\Address::class)->create([
'entity_id' => $entity
]);
$user->entities()->save($entity);
});