tako's avatar
Level 1

Order by with pagination

Is there a way to sort all the columns from all pages ? I use this but it only sort in the current page and I would like to sort it from the first page to the last one.

Product::orderByDesc('updated_at')->paginate(30); 
0 likes
3 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Be aware that two records can have the same updated_at

Product::orderByDesc('updated_at')->orderBy('id')->paginate(30); 

tako's avatar
Level 1

@Sinnbeck thanks but is it possible to sort them even if there is data in others paages that are not loaded or not then ?

Sinnbeck's avatar

@tako It will always be ordered? Go to page 2 and check the query being run using debugbar.. It should have ORDER BY

Please or to participate in this conversation.