Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

JohnSonandrla's avatar

How to sort a Laravel query builder result by multiple columns?

I want to sort multiple columns in Laravel 4 by using the method orderBy() in Laravel Eloquent. The query will be generated using Eloquent like this:

SELECT * FROM mytable ORDER BY coloumn1 DESC, coloumn2 ASC How can I do this?

0 likes
1 reply
Sinnbeck's avatar

Laravel 4? Thats quite old :)

Dont know if this syntax was valid back then, but give it a shot

MyModel::orderByDesc('coloumn1')->orderBy('coloumn2')->get();

Please or to participate in this conversation.