I need to get an array of a list of random ids from a model, I do:
User::all('id')->random(5)->flatten()->toArray()
But this still out a multi array:
0 => array:1 [
"id" => 20
]
1 => array:1 [
"id" => 69
]
....
Im looking for something like:
[20, 69]
Try pluck()
:
User::all('id')->random(5)->pluck('id')->toArray();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With