Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

laravel seeding with relationships

//create 10 users
factory(User::class, 10)->create()->each(function ($user) {
    //create 5 posts for each user
    factory(Post::class, 5)->create(['user_id'=>$user->id]);
});
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #laravel #seeding #relationships
ADD COMMENT
Topic
Name
7+8 =