Order a cursor page by id

cursorPaginate needs a unique order. id is unique. A duplicated published_at skips and repeats rows.

For your AI agent

Copies a prompt. Paste it into the AI agent you already have open.

Read https://laravel-vuejs.space/laravel-order-by-id-vue.md
cursorPaginate needs a unique order. id is unique. A duplicated published_at skips and repeats rows.
Do not orderBy('publishedat')->orderBy('id') and then cursor on both unless you have read the guide and the links still match.
Do not sort the page again in Vue.
Show the diff. Do not commit.
On this page · 3 sections
  1. The fix
  2. What to avoid
  3. FAQ

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.

Who it's for: Laravel + Vue developers on Inertia

Applies to: Laravel 13 · Inertia 3 · Vue 3

The fix#

php
$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.

Found this useful?

Ask questions, share what you built.

Join thousands of Laravel and Vue developers in our Facebook group, or get new posts in your Telegram feed. Sharing this article helps too.

Keep reading

Newsletter

Get the best of Laravel & Vue, once a month.

One short email with new guides, release notes worth reading and hand-picked community links. No spam, unsubscribe any time.