Example #1
0
 /**
  * @inheritdoc
  */
 public function getNext()
 {
     $last = $this->paginator->getCollection()->last();
     if (is_null($last)) {
         return 0;
     }
     return (int) $last->id;
 }
Example #2
0
 public function paginatedCollection(Paginator $paginator, $transformer = null, $resourceKey = null)
 {
     $paginator->appends(\Request::query());
     $resource = new Collection($paginator->getCollection(), $this->getTransformer($transformer), $resourceKey);
     $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
     return $this->manager->createData($resource)->toArray();
 }
 function it_gets_the_next_position(Paginator $paginator, Collection $collection)
 {
     $next = 4;
     $model = new \stdClass();
     $model->id = $next;
     $paginator->getCollection()->shouldBeCalledTimes(1)->willReturn($collection);
     $collection->last()->shouldBeCalledTimes(1)->willReturn($model);
     $this->getNext()->shouldReturn($next);
 }
Example #4
0
 static function answerOkByPager(Paginator $paginator)
 {
     if ($paginator->getLastPage() == $paginator->getCurrentPage()) {
         $next_page = null;
     } else {
         $next_page = $paginator->getCurrentPage();
     }
     $next_page_url = $next_page ? \Request::url() . '?page=' . $next_page : null;
     return parent::json(['meta' => ['code' => 200], 'pagination' => ['next_url' => $next_page_url, 'next_page' => $next_page], 'data' => $paginator->getCollection()->toArray()], 200, [], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
 }
Example #5
0
 /**
  * @param AbstractPaginator|LengthAwarePaginator|Paginator $paginator
  * @return \League\Fractal\Resource\Collection
  */
 protected function transformPaginator($paginator)
 {
     $collection = $paginator->getCollection();
     $resource = new Collection($collection, $this->getTransformer(), $this->resourceKeyCollection);
     $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
     return $resource;
 }
Example #6
0
 protected function formatResponse(Paginator $paginator, BaseTransformer $transformer = null)
 {
     $data = $paginator->getCollection();
     if (!is_null($transformer)) {
         $data = $this->transformData($data, $transformer);
     }
     $this->appendsQueryString($paginator);
     return ["data" => $data, "meta" => ["pagination" => $this->getPagination($paginator)]];
 }
Example #7
-15
 /**
  * Respond with a paginator, and a transformer.
  *
  * @param Paginator $paginator
  * @param callable|\League\Fractal\TransformerAbstract $transformer
  * @param string $resourceKey
  * @param array $meta
  * @return \Illuminate\Http\Response
  */
 public function withPaginator(Paginator $paginator, $transformer, $resourceKey = null, $meta = [])
 {
     $resource = new Collection($paginator->getCollection(), $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());
 }