I'm using the following code to create 20 posts, each of which has 3 comments.
Post::factory()
->times(20)
->has(Comment::factory()->times(3))
->create()
Instead I'd like to create 20 posts, each of which has a random number of comments (e.g. post 1 has 2 comments, post 2 has 4 comments, etc.)
This did not work, each post had the same (random) number of comments.
Post::factory()
->times(20)
->has(Comment::factory()->times(rand(1, 5)))
->create()
How can I achieve this?