Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

syntaxerron's avatar

How to include meta and links in Laravel API Resource Collection?

I am building an API for an SPA and I used Laravel API Resources with pagination. I have been using it on my previous projects but on the latest update, the meta data and links are gone. I am using the latest version of Laravel 7.

I used this on my previous projects when retrieving a resource collection: UserResource::collection(User::all());

which returns:

current_page: 1
data: [{…}, __ob__: Observer]
first_page_url: "http://127.0.0.1:8000/api/v1/users?page=1"
from: 1
last_page: 1
last_page_url: "http://127.0.0.1:8000/api/v1/users?page=1"
next_page_url: null
path: "http://127.0.0.1:8000/api/v1/users"
per_page: "10"
prev_page_url: null
to: 1
total: 1

But now, there are no more links and meta data returned with the collection just like the previous implementation:

data: [{…}]

The documentation recommends to use dedicated resource to represent the collection: php artisan make:resource UserCollection and use:

return new UserCollection(User::all());

I was a bit confused with the documentation. Does anybody know the proper way of returning api resource collection just like before with the links and meta data using the new recommended way from the documentation?

0 likes
2 replies
syntaxerron's avatar

My bad. I used paginate on my code, I forgot to include it in my post. Still no meta/links/paginate data included.

Please or to participate in this conversation.