Laravel collection sortBy not taking effect

A huge fail on my part, my pretty print JSON chrome extension was messing with the display order, viewing the raw response showed they were in fact sorted correctly... ::facepalm::


To extend on @Titan's answer, i guess the extensions/ postman maintain the array indexing order. Not really sure.

To get rid of that

return $collection->values();

Here is an example

$arr = collect([
  0 => [
      'name' => 'foo',
      'weight' => 70
  ],
  1 => [
      'name' => 'bar',
      'weight' => 80
  ]
 ]);

return $arr->sortByDesc('weight');

the extension will still keep the index order

return $arr->sortByDesc('weight')->values();

This will get the desired order.