Paginate an API resource for Vue

A resource collection of a paginator already includes links and meta. Do not paginate those rows again in Vue.

For your AI agent

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

Read https://laravel-vuejs.space/eloquent-api-resource-pagination-vue.md
A resource collection of a paginator already includes links and meta. Do not paginate those rows again in Vue.
Do not paginate those rows again in Vue.
Do not paginate in Vue with the full collection loaded above the resource.
Show the diff. Do not commit.
On this page · 3 sections
  1. The fix
  2. What to avoid
  3. FAQ

People searching “Laravel API resource pagination Vue” wrap a paginator and then read data.data or rebuild the links. When the collection is a paginator, Laravel keeps data, links, and meta. The API resource guide shows the shape. The pagination guide is what changes if you switch paginator.

TL;DR

  • A resource collection of a paginator already includes links and meta.
  • Do not paginate those rows again in Vue.
  • Do not PostResource::collection($posts->items()).
  • Do not paginate in Vue with the full collection loaded above the resource.

Who it's for: Laravel + Vue developers

Applies to: Laravel 13 · Vue 3

The fix#

php
$posts = Post::query()->orderBy('id')->paginate(12);

return PostResource::collection($posts);

meta.last_page is present because this is paginate. A Vue page that only needs next and previous should not assume last_page after you switch to simplePaginate.

What to avoid#

Gotcha

Do not PostResource::collection($posts->items()). You dropped the links. Do not paginate in Vue with the full collection loaded above the resource. The page query is the paginator.

FAQ#

How do I paginate an API resource for Vue?

A resource collection of a paginator already includes links and meta. Do not paginate those rows again in Vue.

What goes wrong with Laravel API resource pagination Vue?

Many developers wrap a paginator and then read data. Do not PostResource::collection($posts->items())`.

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.