/** * Search the database for the entity with a limit and * a offset * * @param int $page * @param int $paging * @return mixed */ public function fetchPage($page = 1, $paging = 10) { try { $collection = $this->gateway->findAllByPage($page, $paging); if (!$collection) { return $this->payload->notFound(['collection' => $collection]); } //Set the pagination $count = $this->gateway->count(); $pagination['current'] = (int) $page; $pagination['pages'] = ceil($count / (int) $paging); return $this->payload->found(['collection' => $collection, 'pagination' => $pagination]); } catch (Exception $e) { return $this->payload->error(['exception' => $e, 'page' => $page, 'paging' => $paging]); } }