/** * Grab the actual instances. * * @return mixed */ public function getInstances() { // First create the params object with stuff like search, sorting $this->createParams(); // And finally grab the entities if ($this->entity->list_template->paginate) { // Pagination config is set: grab the current page $this->pagination = $this->repo->paginate($this->entity->list_template->paginate, $this->params); $this->count = $this->pagination->total(); return $this->pagination->items(); } else { // Grab all entities of this kind from DB $instances = $this->repo->listAll($this->params); $this->count = sizeof($instances); return $instances; } }
/** * @param Paginator $paginatorData * @param $data * @return mixed */ public function respondWithPagination($paginatorData, $data) { $data = array_merge($data, ['paginator' => ['total_count' => count($paginatorData->items()), 'total_pages' => ceil(count($paginatorData->items()) / $paginatorData->perPage()), 'current_page' => $paginatorData->currentPage(), 'limit' => $paginatorData->count(), 'next_page_url' => $paginatorData->nextPageUrl()]]); return $this->respond($data); }