Can someone explain to me why this works
$profile = Profile::all()->random(8);
and this doesn't work
$profile = Profile::where('gender_id', '=', 1)->random(8);
I get the error saying
Call to undefined method Illuminate\Database\Query\Builder::random()
You should use:
$profile = Profile::where('gender_id', '=', 1)->get()->random(8);
Because random()
function gets random items from collection. Reference
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments