private function filter(\Illuminate\Database\Eloquent\Builder $_db) { $_db->take($this->limit); if (Request::get('offset')) { $_db->skip(Request::get('offset')); } return $_db; }
private function filter(\Illuminate\Database\Eloquent\Builder $_db) { $_db->take($this->limit); if (Request::get('offset')) { $_db->skip(Request::get('offset')); } if (Request::get('q')) { $_db->where('description', 'like', Request::get('q') . '%'); } return $_db; }
public function getItems($limit, $offset) { $builder = $this->query->getQuery(); if ($builder->groups || $builder->unions) { $row = DB::selectOne("SELECT COUNT(*) qty FROM (" . $this->query->toSql() . ") sub", $this->query->getBindings()); $total = (int) $row->qty; } else { $total = $this->query->count(); } $pageOfItems = $this->query->skip($offset)->take($limit)->get(); return [$pageOfItems, $total]; }
/** * Set clauses on the query builder * * @return $this */ protected function setClauses() { foreach ($this->wheres as $where) { $this->query->where($where['column'], $where['operator'], $where['value']); } foreach ($this->whereIns as $whereIn) { $this->query->whereIn($whereIn['column'], $whereIn['values']); } foreach ($this->orderBys as $orders) { $this->query->orderBy($orders['column'], $orders['direction']); } if (isset($this->take) and !is_null($this->take)) { $this->query->take($this->take); } if (isset($this->skip) and !is_null($this->skip)) { $this->query->skip($this->skip); } if (isset($this->paginate) and !is_null($this->paginate)) { $this->query->paginate($this->paginate); } return $this; }
/** * Возвращает коллекцию в виде пагинации * * @param int $page * @param int $limit */ public function pagination($page, $limit = 10) { /** * @var \Illuminate\Support\Collection $data */ $countTotal = $this->_query->count(); $this->_query->skip($limit * $page - $limit); $this->_query->limit($limit); $data = collect(); foreach ($this->_query->get() as $key => $instance) { $_listRow = []; foreach ($this->columns->getColumns() as $column) { $_listRow[$column->getKey()] = $column->getValues($instance); } $buttons = $this->filterAction($instance); if (count($buttons)) { $_listRow = array_merge($_listRow, [GridColumn::ACTION_NAME => implode('', $buttons)]); } $data->offsetSet($key, $_listRow); } return new \Illuminate\Pagination\LengthAwarePaginator($data, $countTotal, $limit, $page, ['path' => \Illuminate\Pagination\Paginator::resolveCurrentPath(), 'pageName' => 'page']); }
/** * Datatable paging * * @return null */ protected function paging() { if (!is_null($this->input['start']) && !is_null($this->input['length']) && $this->input['length'] != -1) { $this->query->skip($this->input['start'])->take((int) $this->input['length'] > 0 ? $this->input['length'] : 10); } }
public function getItems($limit, $offset) { $total = $this->query->getQuery()->getCountForPagination(); $pageOfItems = $this->query->skip($offset)->take($limit)->get(); return [$pageOfItems, $total]; }
/** * Offset the results * * @param \Illuminate\Database\Eloquent\Builder $query * @param int $offset * @return \Illuminate\Database\Eloquent\Builder */ public function scopeOffset(Builder $query, $offset) { return $query->skip($offset); }
/** * Skip a certain amount of rows * * @param integer $skip * @return $this */ public function skip($skip) { $this->builder = $this->builder->skip($skip); return $this; }
/** * @param PaginationParameters $paginationParameters * @param Builder $query * @return Builder */ public function buildPagination(PaginationParameters $paginationParameters, Builder $query) { $page = $paginationParameters->getPage(); $limit = $paginationParameters->getLimit(); return $query->skip($limit * ($page - 1))->take($limit); }