Thursday, March 9, 2017

Laravel 5.4 sortBy() not working

Laravel Doc

My laravel Version const VERSION = '5.4.15';

HomeController

$collection = collect([
    ['name' => 'Desk', 'price' => 200],
    ['name' => 'Chair', 'price' => 100],
    ['name' => 'Bookcase', 'price' => 150],
]);

$sorted = $collection->sortBy('price');

$sorted->values()->all();

return $sorted;

Result

{
 0: {
 name: "Desk",
 price: 200
 },
 1: {
 name: "Chair",
 price: 100
 },
 2: {
 name: "Bookcase",
 price: 150
 }
}

What i miss? why not working sortBy?



via Goran Siriev

Advertisement