Skip to content

Instantly share code, notes, and snippets.

View SabrinaMarkon's full-sized avatar
🎯
Focusing

Sabrina Markon SabrinaMarkon

🎯
Focusing
View GitHub Profile
@SabrinaMarkon
SabrinaMarkon / laravel5.2-eloquent-orderBy-muliple-columns.txt
Last active August 22, 2016 18:59
Sabrina Notes - Laravel 5.2 - Eloquent - How to order database SELECT results by multiple columns
Laravel 5.2 - Eloquent - How to order database SELECT results by multiple columns
---------------------------------------------------------------------------------
Chain together using orderBy with the columns being sorted in the order they are chained, as in the example line below:
$contents = ModelName::orderBy('columnA', 'asc')->orderBy('columnB', 'desc')->get();
If $contents is returned to the view now, all rows of the table will be sorted first according to the ascending values of
columnA, followed by a second sort of the desc values of column B.