第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在 Laravel 上填充 META 和 LINKS 分頁(yè)?

如何在 Laravel 上填充 META 和 LINKS 分頁(yè)?

PHP
侃侃爾雅 2021-09-18 16:01:01
我需要幫助在 laravel eloquent 上填充這種分頁(yè)。{  "meta": {    "count": 10,    "total": 100  },  "links": {    "first": "http://localhost/page[limit]=10&page[offset]=0",    "last": "http://localhost/page[limit]=10&page[offset]=10",    "next": "http://localhost/page[limit]=10&page[offset]=10",    "prev": "null"  },  "data": [    {      "type": "checklists",      "id": "1"    }  ]}我在 Laravel Eloquent 上試過(guò)這段代碼。$data = Model::select('type','id')->paginate(10);return response()->json(    [        'data' => $data    ],200);但它顯示不同的格式,填充的數(shù)據(jù)沒(méi)有 META 和 LINKS 模式。{    "data": {        "current_page": 1,        "data": [            {                "type": "Mechanical Equipment Sales Representative",                "id": 1            }       ],        "first_page_url": "http://localhost?page=1",        "from": 1,        "last_page": 4,        "last_page_url": "http://localhost?page=4",        "next_page_url": "http://localhost?page=2",        "path": "http://localhost",        "per_page": 10,        "prev_page_url": null,        "to": 10,        "total": 39    }}怎么做?請(qǐng)幫忙?
查看完整描述

1 回答

?
慕容708150

TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超4個(gè)贊

您可以使用 API 資源:https : //laravel.com/docs/eloquent-resources#pagination


創(chuàng)建集合資源:


php artisan make:resource ModelCollection

在您的控制器中使用它:


$data = Model::select('type','id')->paginate(10);


return new ModelCollection($data);

對(duì)于 Lumen,創(chuàng)建一個(gè)app/Http/Resources/ModelCollection.php文件:


<?php


namespace App\Http\Resources;


use Illuminate\Http\Resources\Json\ResourceCollection;


class ModelCollection extends ResourceCollection

{

    /**

     * Transform the resource collection into an array.

     *

     * @param  \Illuminate\Http\Request  $request

     * @return array

     */

    public function toArray($request)

    {

        return parent::toArray($request);

    }

}


查看完整回答
反對(duì) 回復(fù) 2021-09-18
  • 1 回答
  • 0 關(guān)注
  • 144 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)