Coolone3000
3 months ago
406
2
Laravel

Pagination data missing from api resource.

Posted 3 months ago by Coolone3000
  • Laravel Version: 7.8.1
  • PHP Version: 7.4.2
  • Database Driver & Version: MySql & 5.7

Description:

When sending an eloquent query to an api resource with pagination the pagination data is missing from the result.

Laravel 6.x

{
  "current_page": 1,
  "data": [
    {
      "id": 10000196,
      "name": "John Doe",
    }
  ],
  "first_page_url": "http://www.mysite.com/users?page=1",
  "from": 1,
  "next_page_url": "http://www.mysite.com/users?page=2",
  "path": "http://www.mysite.com/users",
  "per_page": 1,
  "prev_page_url": null,
  "to": 1
}

Laravel 7.x

[
  {
    "id": 10000196,
    "name": "John Doe",
  }
]

Steps To Reproduce:

Using a fresh laravel app with the default user table and at least one user in the database.

$resource = \App\Http\Resources\User::collection(\App\User::query()->paginate(1));

dd($resource->toJson());

Please sign in or create an account to participate in this conversation.