If you need a specific order in which you want to include records, you will need to use Collection methods :
, sortBy , - :
$ids = [ 5, 6, 0, 1];
$sorted = $collection->sortBy(function($model) use ($ids) {
return array_search($model->getKey(), $ids);
});
shuffle.
$collection = collect([1, 2, 3, 4, 5]);
$shuffled = $collection->shuffle();
$shuffled->all();
. Laravel Docs shuffle / sortBy.
, ->inRandomOrder() 5.2 , ->orderBy(DB::raw('RAND()')).