Laravel JSON分页:如何从下一个/上一个链接中删除箭头



我使用Laravel8.20.1,我的API路由返回一个分页的JSON响应。

有没有比str_replace()更好的方法来去除标签上的箭头?

routes/api.php:

Route::middleware('auth:sanctum')->get('/items', function (Request $request) {
return new ItemCollection(Item::paginate(5));
});

响应.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
}

Next和Previous的标签在翻译文件resources/lang/en/pagination.php中。如果您查看IlluminatePaginationLengthAwarePaginator::linkCollection,您可以看到它正在构建响应的链接部分。

相关内容

最新更新