for some time i have been trying to figure out how to achieve a custom order in my eloquent (collection?): This is my collection (Notice I did not make use of ->get() because in the latter part of the function, im using this to extend the query/collection)
$ads = Ad::whereIn('ad_type',[2,3,1]); <-- This is my Desired Output as well.
I have multiple Elements in my Ad table with each ad_type.
So i have tried:
$ads1 = Ad::where('ad_type',1);
$ads2 = Ad::where('ad_type',2);
$mergedAds = $ads1->merge($ads2);
But i just get:
'Call to undefined method Illuminate\Database\Query\Builder::merge()'
Next i tried leaving $ads1 as it is and adding:
$ads2 = sortBy(function($ads) use ($ad_types) {
return array_search($ads->getKey(), $ad_types);
});
but well, its not an array so this cant work. Can anyone put me in the right direction? And maybe explain what the difference between Collection, Eloquent Collection and Query might be so i can understand this better. Thank you so much in advance. (Why I ask this question: I have seen people doing collect() or new Collection() and i dont know what this is, neither did I really find out anything useful)