Albertopeinado's avatar

Pagination data not included in API Resources

I have no clue what could be happening here.

I have ProductCollection that returns the pagination data correctly if the data is returned from the route directly.

Route::get('/products', function () { return new ProductCollection(Product::paginate()); });

However, if the data is returned from controller as a json response like this, it does not include the pagination data:

return response()->json(new ProductCollection(Product::paginate()), 200);

Does anyone know what may be happening here?

0 likes
1 reply
martinbean's avatar

@albertopeinado You don’t need to wrap resources in JSON responses. Just return the resource. It’s literally their job.

Please or to participate in this conversation.