Skip to content
Advertisement

Sort By highest ID in Laravel?

I need to sort posts by highest id :/. Currently, the code sorts them by the lowest ID.

$posts->sortBy('id');

How can I do that?

Advertisement

Answer

$posts->sortByDesc('id');

Source: Laravel Collections

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