# Order a cursor page by id

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

- URL: https://laravel-vuejs.space/laravel-order-by-id-vue
- Author: Anass Ez-zouaine (https://laravel-vuejs.space/author/anass-ez-zouaine)
- Published: 2026-10-11
- Topics: Laravel, VueJs, Inertia

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](https://laravel-vuejs.space/laravel-vue-pagination) 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

**Q: 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.

**Q: 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.
