Laravel pagination has different structure when returned by itself vs. through an API resource.
return $query->paginate(request('per_page'));
returns pagination with this structure:
{
"current_page": 1,
"data":[...],
"first_page_url": "http://user-service.test/api/users?page=1",
"from": 1,
"last_page": 1,
"last_page_url": "http://user-service.test/api/users?page=1",
"next_page_url": null,
"path": "http://user-service.test/api/users",
"per_page": 15,
"prev_page_url": null,
"to": 10,
"total": 10
}
On the other hand, sending the paginator through an API resource like this:
return new UserCollection($query->paginate(request('per_page')));
returns this structure:
{
"data":[...],
"links": {
"first": "http://user-service.test/api/users/searches?page=1",
"last": "http://user-service.test/api/users/searches?page=6",
"prev": null,
"next": "http://user-service.test/api/users/searches?page=2"
},
"meta": {
"current_page": 1,
"from": 1,
"last_page": 6,
"path": "http://user-service.test/api/users/searches",
"per_page": "1",
"to": 1,
"total": 6
}
}
I need to have the same structure for both types. Am I doing something wrong?