I'm using Laravel 8.20.1
and my API route returns a paginated JSON response.
Is there a better way than str_replace()
to remove the arrows from the labels?
routes/api.php
:
Route::middleware('auth:sanctum')->get('/items', function (Request $request) {
return new ItemCollection(Item::paginate(5));
});
response.data.meta
{
"current_page": 1,
"from": 1,
"last_page": 3,
"links": [
{
"url": null,
"label": "« Previous",
"active": false
},
....
{
"url": "http://localhost/api/items?page=2",
"label": "Next »",
"active": false
}
],
"path": "http://localhost/api/items",
"per_page": 5,
"to": 5,
"total": 15
}
Those labels for Next and Previous are in the translation files, resources/lang/en/pagination.php
. If you look at Illuminate\Pagination\LengthAwarePaginator::linkCollection
you can see it building the links part of the response.