Laravel 8 数据包裹和分页
当在资源响应中返回分页集合时,即使你调用了 withoutWrapping
方法, Laravel 也会将你的资源数据包裹在 data
键中。这是因为分页响应中总会有 meta
和 links
键包含着分页状态信息:
{
"data": [
{
"id": 1,
"name": "Eladio Schroeder Sr.",
"email": "therese28@example.com",
},
{
"id": 2,
"name": "Liliana Mayert",
"email": "evandervort@example.com",
}
],
"links":{
"first": "http://example.com/pagination?page=1",
"last": "http://example.com/pagination?page=1",
"prev": null,
"next": null
},
"meta":{
"current_page": 1,
"from": 1,
"last_page": 1,
"path": "http://example.com/pagination",
"per_page": 15,
"to": 10,
"total": 10
}
}