On December 9, 2020 . By CodimTh Category: Web Laravel Laravel orderBy on a relationship To sort by ASC: $collection->sortBy('field'); To sort by DESC: $collection->sortByDesc('field'); Examples: $users = User::all()->with('role')->get()->sortByDesc('role.name'); $users = User::all()->with('groupe')->get()->sortBy('groupe.name'); Tags : Laravel Laravel tutoriel Tips Laravel Previous Postgit changes not staged for commitNext PostHow to use Laravel Telescope Comments Add new comment Your name Subject Comment About text formats Restricted HTML Leave this field blank
Comments