Laravel 8 數(shù)據(jù)包裹和分頁

2021-07-08 11:55 更新

當(dāng)在資源響應(yīng)中返回分頁集合時,即使你調(diào)用了 withoutWrapping 方法, Laravel 也會將你的資源數(shù)據(jù)包裹在 data 鍵中。這是因為分頁響應(yīng)中總會有 metalinks 鍵包含著分頁狀態(tài)信息:

{
    "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
    }
} 
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號