Example #1
0
 /**
  * todo make a better html paginator
  * @param \Illuminate\Contracts\Pagination\LengthAwarePaginator $collection
  * @return string
  */
 function paginate(\Illuminate\Contracts\Pagination\LengthAwarePaginator $collection)
 {
     $current = $collection->currentPage();
     $per = $collection->perPage();
     $count = $collection->count();
     $from = $current * $per;
     $to = $from + $count;
     $html = '';
     // "From {$from} to {$to}";
     $previous = $current > 1 ? $collection->url("?page=" . ($current - 1)) : false;
     $next = $collection->hasMorePages() ? $collection->nextPageUrl() : false;
     if ($previous) {
         $html .= '<li><a href="' . $previous . '">prev</a></li>';
     }
     if ($next) {
         $html .= '<li><a href="' . $next . '">next</a></li>';
     }
     return '<ul>' . $html . '</ul>';
 }
Example #2
0
 /**
  * Returns the Pagination Data
  *
  * @param $paginatedItems
  *
  * @return array
  */
 protected function getPaginationData(LengthAwarePaginator $paginatedItems)
 {
     $paginationInfo = ['items' => $paginatedItems->total(), 'pages' => ceil($paginatedItems->total() / $paginatedItems->perPage()), 'each' => $paginatedItems->perPage(), 'current' => $paginatedItems->currentPage()];
     return $paginationInfo;
 }
 /**
  * Get the current page from the paginator.
  *
  * @return int
  */
 protected function currentPage()
 {
     return $this->paginator->currentPage();
 }
 /**
  * Is the current page the first page?
  *
  * @param \Illuminate\Pagination\Paginator $paginator
  *
  * @return bool
  */
 protected function isFirstPage(LengthAwarePaginator $paginator)
 {
     return $paginator->currentPage() === 1;
 }
 /**
  * Get the current page.
  *
  * @return int
  */
 public function getCurrentPage()
 {
     return $this->paginator->currentPage();
 }
 protected function respondWithPagination(LengthAwarePaginator $lenhthAwarePaginator, $data)
 {
     $data = array_merge($data, ['paginator' => ['total_count' => $lenhthAwarePaginator->total(), 'total_pages' => ceil($lenhthAwarePaginator->total() / $lenhthAwarePaginator->perPage()), 'current_page' => $lenhthAwarePaginator->currentPage(), 'limit' => $lenhthAwarePaginator->perPage()]]);
     return $this->respond($data);
 }
Example #7
0
 /**
  * @param $data
  * @param LengthAwarePaginator $pagination
  *
  * @return array
  */
 public static function withPaginationData($data, LengthAwarePaginator $pagination)
 {
     $data = ['data' => $data, 'pagination' => ['total_count' => $pagination->total(), 'total_pages' => ceil($pagination->total() / $pagination->perPage()), 'current_page' => $pagination->currentPage(), 'limit' => (int) $pagination->perPage()]];
     return $data;
 }
 /**
  * @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()]);
 }
 /**
  * Will result in an array with a paginator
  *
  * @param LengthAwarePaginator $items   The paginated items
  * @param array                $data    The data
  * @param array                $headers The headers that should be send with the JSON-response
  *
  * @return \Illuminate\Http\JsonResponse The JSON-response with the paginated results
  */
 protected function respondWithPagination(LengthAwarePaginator $items, $data, $headers = [])
 {
     $data = array_merge($data, ['pagination' => ['total_count' => $items->total(), 'total_pages' => $items->lastPage(), 'current_page' => $items->currentPage(), 'limit' => $items->perPage()]]);
     return $this->respond($data, $headers);
 }
Example #10
0
 /**
  * {@inheritdoc}
  */
 public function canonicalUrl()
 {
     return $this->posts->url($this->posts->currentPage());
 }