Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SabrinaMarkon/916e3a3ed0c4d7c2d188a70bb16ada5b to your computer and use it in GitHub Desktop.
Save SabrinaMarkon/916e3a3ed0c4d7c2d188a70bb16ada5b to your computer and use it in GitHub Desktop.
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment