/** * Respond with a paginator, and a transformer. * * @param LengthAwarePaginator $paginator * @param callable|\League\Fractal\TransformerAbstract $transformer * @param string $resourceKey * @param array $meta * @return ResponseFactory */ public function withPaginator(LengthAwarePaginator $paginator, $transformer, $resourceKey = null, $meta = []) { $resource = new Collection($paginator->items(), $transformer, $resourceKey); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); foreach ($meta as $metaKey => $metaValue) { $resource->setMetaValue($metaKey, $metaValue); } $rootScope = $this->manager->createData($resource); return $this->withArray($rootScope->toArray()); }
/** * @param LengthAwarePaginator $articles Articles to change to an ArticleCollection * @return ArticleCollection */ private function paginate(LengthAwarePaginator $articles) { return new ArticleCollection($articles->items(), $articles->total(), $articles->perPage(), $articles->currentPage(), ['lastPage' => $articles->lastPage(), 'path' => $articles->resolveCurrentPath()]); }
/** * @param LengthAwarePaginator $paginator * @param \League\Fractal\TransformerAbstract|\Closure $transformer * @param string $resourceKey * @return mixed */ public function respondPaginatedCollection(LengthAwarePaginator $paginator, $transformer = null, $resourceKey = null) { $paginator->appends($this->request->query()); $resource = new Collection($paginator->items(), $this->getTransformer($transformer), $resourceKey); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $rootScope = $this->manager->createData($resource)->toArray(); return $this->respondWithArray($rootScope); }