Skip to content
Advertisement

MySQL order by field in Eloquent

When I want to define a custom sort order in a MySQL query I can do something like this:

What would be the Eloquent ORM version of that?

UPDATE:

This is the solution and it also works when ordering on various fields:

Advertisement

Answer

Using either DB::raw() or orderByRaw directly should work:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement