本文整理汇总了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);
}
示例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();
}