If a User has many posts, and a post belongs to user, it's simple to do:
$factory->define(App\Post::class, function ($faker) {
return [
'title' => $faker->title,
'content' => $faker->paragraph,
'user_id' => function () {
// Creates a User for every Post
return factory(App\User::class)->create()->id;
}
];
});
How do I accomplish the opposite? Instead, creating say 5 posts when a user is created and associating that post to the newly created user?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire