chinh2597's avatar

Cursor pagination add orderBy condition lead to error with old cursor

In the beginning, I'm using orderByDesc("id")->cursorPaginate(10) to create pagination, but after that i need to sort by another field (for example: score, this field is not unique) so i change query like: orderByDesc("score")->orderByDesc("id")->cursorPaginate(10).

It work fine if client is new, but with exist client, their cursor parameter has only id so laravel throw an UnexpectedValueException exception (because it's missing the last score value): github.com/illuminate/pagination/blob/master/Cursor.php#L47.

How can i change the sort condition on server and make it work with the old client cursor

0 likes
2 replies
chinh2597's avatar

@SilenceBringer yes, for sure, my problem is laravel using cursor to store last order data so when i add another sort (orderBy score) the old cursor doesn't have that (last score value from previous page) and throw an exception

Please or to participate in this conversation.