/**
  * @param Request $request
  * @return mixed
  */
 public function index(Request $request)
 {
     if ($request->query->get('paginate') === 'false') {
         return $this->repository->all();
     }
     return $this->repository->paginate($request->query->get('limit'));
 }
Exemplo n.º 2
0
 public function paginate($limit = null, $columns = array('*'))
 {
     $paginator = parent::paginate($limit, $columns);
     if ($this->with_relation_count) {
         $id = [];
         foreach ($paginator->items() as $item) {
             $id[] = $item->id;
         }
         foreach ($this->relations as $relation => $options) {
             $tmp = $this->getRelationRecordCount($relation, $relation)->whereIn('main.id', $id)->get()->all();
             $tmp2 = [];
             foreach ($options['fields'] as $field) {
                 foreach ($tmp as $record) {
                     $tmp2[$record->id] = $record->{$field};
                 }
                 foreach ($paginator->items() as &$item) {
                     $item[$field] = !empty($tmp2[$item->id]) ? $tmp2[$item->id] : 0;
                 }
             }
             unset($item);
         }
     }
     return $paginator;
 }