count(10)->create(); if (User::count() > 0 && BlogPost::count() > 0) { $blogPosts->each( function ($blogPost) { User::inRandomOrder() ->first() ->author_of_blog_post() ->attach($blogPost->id); } ); $comments = BlogPostComment::factory()->count(5)->make(); $comments->each( static function ($comment): void { $comment->author()->associate( User::inRandomOrder() ->first() ->id ); $comment->blog_post()->associate( BlogPost::inRandomOrder() ->first() ->id ); $comment->saveOrFail(); } ); $blogPosts = BlogPost::all(); $blogPosts->each( static function ($blogPost): void { $tags = Tag::factory()->count(5)->create(); $tagsIds = collect($tags)->map(fn($curTag) => $curTag['id']); $blogPost->tags()->attach($tagsIds); } ); } } }