Exemple #1
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 total.
  *
  * @return int
  */
 public function getTotal()
 {
     return $this->paginator->total();
 }
 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);
 }
 /**
  * @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);
 }