'Getting a random row in a seed?
In my seed, I want to created 20 rows in my like table...
Like::factory()->count(20)->for(
Post::inRandomOrder()->first() ?? Post::factory(), 'likeable'
)->create();
In the for I get a random post or if no post is available I create one.
The issue is, all 20 rows created in the like table have the same "random" post id, almost as if the random selector is only running once.
Why is this the case?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
