當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Collection::setMeta方法代碼示例

本文整理匯總了PHP中League\Fractal\Resource\Collection::setMeta方法的典型用法代碼示例。如果您正苦於以下問題:PHP Collection::setMeta方法的具體用法?PHP Collection::setMeta怎麽用?PHP Collection::setMeta使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在League\Fractal\Resource\Collection的用法示例。


在下文中一共展示了Collection::setMeta方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: transform

 /**
  * Manage and finalize the data transformation.
  *
  * @param  \League\Fractal\Resource\Item|\League\Fractal\Resource\Collection  $data
  * @param  int  $code
  * @param  array  $meta
  * @return \Illuminate\Http\JsonResponse
  */
 public function transform($data, $code = 200, $meta = [])
 {
     $data->setMeta($meta);
     $manager = new Manager();
     $manager->setSerializer(new DataArraySerializer());
     $response = $manager->createData($data)->toArray();
     return response()->json($response, 200, [], JSON_UNESCAPED_SLASHES);
 }
開發者ID:DoSomething,項目名稱:gladiator,代碼行數:16,代碼來源:ApiController.php

示例2: getPagination

 /**
  * Create FractalCollection payload with pagination.
  *
  * @param \Illuminate\Contracts\Pagination\LengthAwarePaginator $paginator
  * @param null                                                  $transformer
  * @param string|null                                           $resourceKey
  * @return mixed
  */
 public function getPagination(LengthAwarePaginator $paginator, $transformer = null, $resourceKey = null)
 {
     // Append existing query parameter to pagination link
     // @see http://fractal.thephpleague.com/pagination/#including-existing-query-string-values-in-pagination-links
     $queryParams = array_diff_key($_GET, array_flip(['page']));
     foreach ($queryParams as $key => $value) {
         $paginator->addQuery($key, $value);
     }
     $collection = $paginator->getCollection();
     $resource = new FractalCollection($collection, $this->getTransformer($transformer), $this->getResourceKey($resourceKey));
     $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
     if ($meta = $this->getMeta()) {
         $resource->setMeta($meta);
         $this->meta = [];
     }
     if ($includes = $this->getIncludes()) {
         $this->fractal->parseIncludes($this->request->input('include'));
         $this->includes = null;
     }
     return $this->fractal->createData($resource)->toArray();
 }
開發者ID:Kristories,項目名稱:fractal,代碼行數:29,代碼來源:Response.php


注:本文中的League\Fractal\Resource\Collection::setMeta方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。