-
When using Model::paginate() Laravel includes 'links' and 'meta' in respose. GET - /users?name=John {
"users": [
{
"id": 1,
"name": "John Doe",
"email": "[email protected]",
"password": "***",
"created_at": "2021-01-01 00:00:00",
"updated_at": "2021-01-01 00:00:00",
}
],
"links": {
"first": "http://localhost:8000/api/users?page=1",
"last": "http://localhost:8000/api/users?page=10",
"prev": null,
"next": "http://localhost:8000/api/users?page=2"
},
"meta": {
"current_page": 1,
"from": 1,
"last_page": 1,
"links": [
{
"url": "http://localhost:8000/api/users?page=1",
"label": "1",
"active": true
}
],
"path": "http://localhost:8000/api/users",
"per_page": 15,
"to": 1,
"total": 10
}
} While building a REST API, we usually use query params to filter data in index(), the problem is that we lose these parameters when use the Example: |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Good point. We had to unset these links and handle the pagination in FE by changing the page there to avoid issues. |
Beta Was this translation helpful? Give feedback.
-
withQueryString
|
Beta Was this translation helpful? Give feedback.
-
@hulkur I wonder why this is not the default behavior...
|
Beta Was this translation helpful? Give feedback.
withQueryString
{{ $paginator->withQueryString()->links() }}