i have some issues with laravel sortBy ( laravel 5.4 ) .. based on what i read on many websites, it says that for doing multiple sortBy laravel was by using reverse order.. so i try to do that.. but still not working properly..
So here it is.. I have this collection of object...
[{
'product_id' => 468,
'name' => 'abc',
'int_premi' => 10000
'score' => 1000
'rates' => 0,
'views' => 0,
'promo' => null
},{
'product_id' => 472,
'name' => 'bcd',
'int_premi' => 10000
'score' => 1000
'rates' => 0,
'views' => 0,
'promo' => 'Some text here'
},{
'product_id' => 458,
'name' => 'def',
'int_premi' => 10000
'score' => 1000
'rates' => 0,
'views' => 0,
'promo' => 'ABC'
}]
My Goal is to have this objects sorted following this order
score ( asc ) > int_premi ( asc ) > rates ( desc ) > promo ( as boolean ) ( desc ) > views ( desc ) > product_id ( desc )
So i write this code..
$collection->sortByDesc('product_id')->sortByDesc('views')->sortByDesc(function($arr,$k){
return !empty($arr->promo);
})->sortByDesc('rates')->sortBy('int_premi')->sortBy('score')->values()->all()
I'm looking for the result comes with this order
BCD > DEF > ABC
Instead, not following that order..
So is there anyone also facing the same issue with me ? and maybe someone can help me out through this issue ?
Thankyou Very much