Esempio n. 1
0
 /**
  * Paginate the given query.
  *
  * @param int $perPage
  * @param int $currentPage
  * @param array $columns
  * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator 
  * @static 
  */
 public static function paginate($perPage = 15, $currentPage = null, $columns = array())
 {
     return \October\Rain\Database\Builder::paginate($perPage, $currentPage, $columns);
 }
Esempio n. 2
0
 /**
  * Paginate resultset 
  * 
  * @param Builder $query
  * @return Response
  */
 protected function paginateResult(Builder $query)
 {
     try {
         $pageSize = $this->getPageSize();
         if ($pageSize > 0) {
             $paginator = $query->paginate($pageSize);
             return Response::api()->withPaginator($paginator, $this->getTransformer());
         } else {
             return Response::api()->withCollection($query->get(), $this->getTransformer());
         }
     } catch (\Exception $e) {
         $message = $e->getMessage();
         if ($e instanceof QueryException) {
             \Log::error('API endpoint ' . get_class($this) . ' : ' . $e->getMessage());
             $message = 'One or multiple filter fields does not exists in the model';
         }
         return Response::api()->errorInternalError($message);
     }
 }