Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将元添加到分页的集合_Php_Laravel - Fatal编程技术网

Php 将元添加到分页的集合

Php 将元添加到分页的集合,php,laravel,Php,Laravel,你能帮我把meta添加到分页的集合中吗?我得到了一个分页有效的响应。我可以交换页面?=1等等。但是当我得到响应时,没有我需要的元标记。非常感谢。 这是我的提供程序ExtendCollectionServiceProvider: public function boot() { Collection::macro('paginate', function ($perPage, $total = null, $page = null, $pageName = 'page', $queryPa

你能帮我把meta添加到分页的集合中吗?我得到了一个分页有效的响应。我可以交换页面?=1等等。但是当我得到响应时,没有我需要的元标记。非常感谢。 这是我的提供程序ExtendCollectionServiceProvider:

public function boot()
{
    Collection::macro('paginate', function ($perPage, $total = null, $page = null, $pageName = 'page', $queryParams= []) {
        $page = $page ?: LengthAwarePaginator::resolveCurrentPage($pageName);

        return new LengthAwarePaginator($this->forPage($page, $perPage), $total ?: $this->count(), $perPage, $page, [
            'path' => 'articles',
            'pageName' => $pageName,
            'query' => $queryParams
        ]);
    });
}
这是我的控制器:

public function index()
{
    $collection = new ArticlesCollection(ArticleResource::collection(Article::with(['user', 'tags'])->paginate(3)));
    return $collection;
}
我得到的回应是,分页是有效的。我可以交换页面,但没有元数据。我不知道,哪一个是最后一个

{
  "data": [
    {
      "id": 1,
      "user": {
        "id": 1,
        "full_name": "test test@gmail.com",
        "email": "test@gmail.com"
      },
      "slug": "davonte-sawayn-1",
      "name": "1",
      "body": "Aliquam placeat veritatis alias sed et inventore. Animi animi amet recusandae qui voluptates quidem. Eos qui culpa aut molestias.",
      "tags": [
        {
          "id": 6,
          "name": "testTag"
        },
        {
          "id": 1,
          "name": "PHP"
        },
        {
          "id": 2,
          "name": "Laravel"
        }
      ],
      "time": {
        "created_at": "2020-05-05T15:19:26.000000Z",
        "updated_at": "2020-05-05T15:19:26.000000Z"
      }
    },
    {
      "id": 2,
      "user": {
        "id": 1,
        "full_name": "test test@gmail.com",
        "email": "test@gmail.com"
      },
      "slug": "lura-weimann-iii-1",
      "name": "2",
      "body": "Praesentium velit deserunt eaque quia consequatur dolor. Delectus nulla quasi in maiores. Et recusandae sed et magnam aperiam exercitationem dolor et.",
      "tags": [
        {
          "id": 3,
          "name": "Node"
        },
        {
          "id": 2,
          "name": "Laravel"
        }
      ],
      "time": {
        "created_at": "2020-05-05T15:19:26.000000Z",
        "updated_at": "2020-05-05T15:19:26.000000Z"
      }
    },
    {
      "id": 11,
      "user": {
        "id": 1,
        "full_name": "test test@gmail.com",
        "email": "test@gmail.com"
      },
      "slug": "raphaelle-hudson-jr-1",
      "name": "3",
      "body": "Maiores in ullam error odio accusantium rerum aliquam. Numquam explicabo fugiat facilis natus accusantium. Non et perferendis fugit in quas ipsum voluptate sit.",
      "tags": [],
      "time": {
        "created_at": "2020-05-06T12:18:51.000000Z",
        "updated_at": "2020-05-06T12:18:51.000000Z"
      }
    }
  ]
}