本文整理汇总了PHP中League\Fractal\Resource\Collection::setTransformer方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::setTransformer方法的具体用法?PHP Collection::setTransformer怎么用?PHP Collection::setTransformer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Fractal\Resource\Collection
的用法示例。
在下文中一共展示了Collection::setTransformer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
/**
* Get a list of objects
*
* @param Request $request Request object
* @return ResponseInterface Response for request
*/
public function get(Request $request, Fractal $fractal, FractalCollection $collection)
{
$this->beforeRequest($request, func_get_args());
$transformer = $this->getTransformer();
$includes = $request->input('include', '');
$filter = $request->input('filter', false);
$items = $this->getRepository();
if ($filter && is_string($filter)) {
$filter = json_decode($filter, true);
}
$queryFilter = [];
if (!empty($filter)) {
$queryFilter = new QueryFilter($filter, $items->model(), $this->getTransformer());
}
$fractal->parseIncludes($includes);
$resource = $collection->setTransformer($transformer)->setResourceKey($this->getResourceKey());
$paginator = $items->paginate($queryFilter, $transformer->getSafeEagerLoad($fractal->getRequestedIncludes()), app('context'));
$itemCollection = $paginator->getCollection();
$resource->setData($itemCollection);
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return $this->respondWithCollection($fractal->createData($resource));
}