Joined November 2013
·

Alexander Taubenkorb

Vienna
·
·

Posted to Sorting Nested Laravel Collections over 1 year ago

Hi,

The following code should also work (note, that latest() is a shortcut for orderBy('created_at','desc'); see https://github.com/laravel/framework/blob/233196cbef18c45a5775009528ffd8bbcbdf8af5/src/Illuminate/Database/Query/Builder.php#L897 for more information)

$user = User::with(array('transactions' => function($query){ $query->latest(); }))->find($id);</code>

Achievements
9 Karma
0 Total ProTip Views
Interests & Skills