When trying to get a random user id in a factory, it always returns null
despite the DB containing 50
users (created via the User
factory).
'user_id' => User::all()->random()->id
I tried to display the retrieved resource doing this:
dd(User::all()->random())
and the result was quite consistent with what expected
App\User^ {#num #fillable: array:9 [] ... #attributes: array:14 [ "id" => 25 ... ] }
but this other method:
dd( User::all()->random()->id )
always returns null
.