Laravel 5.4 sortBy () does not work when returned as JSON

Laravel doc

My version is laravel 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 when returning as JSON:

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

What did I miss? Why does sortBy not work?

+5
source share

Source: https://habr.com/ru/post/1265249/


All Articles