laravel/framework — pull request #5400 by andrewmile (2014-08-10 06:35:29+00:00)
Title: fixed bug in sortBy where incorrectly formatted object was being returned

The Illuminate\Support\Collection sortBy() method currently reuses the original $results array which means it returns an object that is formatted differently than the Eloquent object passed into the method. It also causes ajax requests to read the response as one model rather than a collection of models.

I declared a new $sorted array and used it to create a new correctly sorted array from the $results keys. This results in returning a sorted Eloquent object of the same format as the one passed into the method.