seyyed_am7's avatar

Pagination and orderBy doesn't work correctly together

I'm using pagination and order data by timestamp (column's name is sort and it can be null). It works fine in local environment but when I'm using that in production, There is some duplicated record in different page. Also, after records that sort's column is filled, loaded. Then it should be ordered by id, but it doesn't work. Is there any solution to solve this?

News::query()->published()->filtered()->with('user')->orderByDesc('sort')->paginate();
0 likes
1 reply
SilenceBringer's avatar

@seyyed_am7 try to use any debug tool to see actual db query

about sorting by id - you can chain many orderBy to do it

->orderByDesc('sort')->orderByDesc('id')->...
1 like

Please or to participate in this conversation.