I wanted to make a post seeder with users and comments as mentioned in the relationship section in the laravel documentation https://laravel.com/docs/5.5/database-testing
$users = factory(App\User::class, 3)
->create()
->each(function ($u) {
$u->posts()->save(factory(App\Post::class)
->create()
->each(function($p){
$p->comments()->save(factory(App\Comment::class,5)
->create()
->each(function($c){
$c->user()->save(factory(App\User::class)
->make()
);
})
);
})
);
}
);
Expected output was to have 3 users having posts with 5 comments each.
But error occurred:
In Builder.php line 2459: Call to undefined method Illuminate\Database\Query\Builder::save()