People searching “Laravel cursor pagination duplicate” order by published_at and then a row appears twice or vanishes. A cursor needs a unique column, or a unique pair. The pagination guide says this. The one line is:
TL;DR
- cursorPaginate needs a unique order.
- id is unique.
- A duplicated published_at skips and repeats rows.
- Do not
orderBy('published_at')->orderBy('id')and then cursor on both unless you have read the guide and the links still match.
The fix#
$posts = Post::query()
->orderBy('id')
->cursorPaginate(12);Two posts can share a published_at. They cannot share an id. If you want newest first and you still need the cursor to be stable, order by id descending rather than by a timestamp that ties.
The Vue page reads next_page_url and prev_page_url. It does not read last_page. That key is not on a cursor paginator.
What to avoid#
Gotcha
Do not orderBy('published_at')->orderBy('id') and then cursor on both unless you have read the guide and the links still match. The safe default is one unique column. Do not sort the page again in Vue. The order is the query.
FAQ#
How do I order a cursor page by id?
cursorPaginate needs a unique order. id is unique. A duplicated published_at skips and repeats rows.
What goes wrong with Laravel cursor pagination duplicate?
Many developers order by published_at and then a row appears twice or vanishes. Do not orderBy('published_at')->orderBy('id') and then cursor on both unless you have read the guide and the links still match.



