本文整理汇总了PHP中Illuminate\Database\Query\Builder::paginate方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::paginate方法的具体用法?PHP Builder::paginate怎么用?PHP Builder::paginate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Query\Builder
的用法示例。
在下文中一共展示了Builder::paginate方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: executeQuery
/**
* 주어진 db query를 실행한다.
*
* @param Builder $query 질의
* @param int|int[]|stdClass $navigation 검색시 사용할 navigation(page, perPage, sort, order) 정보
*
* @return array
*/
protected function executeQuery($query, $navigation = null)
{
// set default
$order = $this->defaultOrder;
$sort = $this->defaultSort;
$perPage = $this->defaultPerPage;
$page = null;
if (is_array($navigation)) {
list($page, $perPage) = $navigation;
} elseif (is_object($navigation)) {
$page = data_get($navigation, 'page', $page);
$perPage = data_get($navigation, 'perPage', $perPage);
$order = data_get($navigation, 'order', $order);
$sort = data_get($navigation, 'sort', $sort);
}
if ($sort !== null) {
$query->orderBy($sort, $order);
}
if ($navigation === null) {
$collection = $query->get();
} elseif ($page !== null) {
$collection = $query->forPage($page, $perPage);
} else {
$collection = $query->paginate($perPage);
}
return $collection;
}
示例2: paginate
/**
* Retrieve all data of repository, paginated
*
* @param null $limit
* @param array $columns
* @return mixed
*/
public function paginate($limit = null, $columns = ['*'])
{
return $this->wrap(function ($limit = null, $columns = ['*']) {
$limit = is_null($limit) ? $this->perPage : $limit;
return $this->model->paginate($limit, $columns);
}, new Action(__METHOD__, func_get_args(), Action::READ));
}
示例3: paginate
/**
* Return a paginated list of results.
*
* @param int|string $amount
* @param int|string $page
* @param int|string $perPage
* @return array
* @throws TableNotSetException
*/
public function paginate($amount, $page, $perPage)
{
if (!$this->query) {
throw new TableNotSetException("You must set a database table to get results from.");
}
return $this->query->paginate($amount, $this->select, $this->key)->all();
}
示例4: paginate
/**
* Execute the query and paginate the results according to request or config
*
* @throws \App\Exceptions\APIQueryException Rethrows any exception that happens on pagination (query execution)
**/
public function paginate()
{
try {
$this->query = $this->query->paginate($this->getPaginationConfig());
} catch (\Exception $e) {
throw new QueryException($e);
}
}
示例5: customPaginate
/**
* Custom Paginate current results, for queries that cannot be paginated using paginate().
*
* @param int $total
* @param int $per_page
*
* @return LengthAwarePaginator
*/
public function customPaginate($total, $per_page = 20)
{
$this->per_page = $per_page;
$this->buildQuery();
$current_page = Paginator::resolveCurrentPage() ? Paginator::resolveCurrentPage() : 1;
$data = $this->query->paginate($per_page)->items();
$pagination = new LengthAwarePaginator($data, $total, $per_page, $current_page, ['path' => Paginator::resolveCurrentPath()]);
return $pagination;
}
示例6: paginate
/**
* Paginate the given query into a simple paginator.
*
* @param int $perPage count of list
* @param array $columns get columns
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
*/
public function paginate($perPage, array $columns = ['*'])
{
if ($this->dynamic === false) {
$this->query->paginate($perPage, $columns);
}
if ($this->proxy === true) {
$this->query = $this->getProxyManager()->get($this->query);
}
return $this->query->paginate($perPage, $columns);
}
示例7: optionAppliedPaginate
/**
* @param \Illuminate\Database\Query\Builder|\Minhbang\Kit\Extensions\Model $query
* @param bool $position
*
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
*/
protected function optionAppliedPaginate($query, $position = false)
{
list($column, $direction) = $this->options->column('sort');
if ($column) {
$query->orderBy($column, $direction);
} else {
if ($position) {
$query->orderPosition();
}
}
return $query->paginate($this->options->get('page_size', 6));
}
示例8: scopeQueryWithParams
/**
* A reusable query to pass params
*
* @param Builder $query
* @param array $queryFilter
*
* @return Builder
*/
public function scopeQueryWithParams($query, $queryFilter)
{
$limit = isset($queryFilter['limit']) ? $queryFilter['limit'] : 10;
$perPage = isset($queryFilter['perPage']);
$orderBy = isset($queryFilter['orderBy']) ? $queryFilter['orderBy'] : 'created_at';
$sortOrder = isset($queryFilter['sortOrder']) ? $queryFilter['sortOrder'] : 'desc';
$query->orderBy($orderBy, $sortOrder);
if ($perPage) {
return $query->paginate($perPage);
}
return $query->take($limit);
}
示例9: build
public function build()
{
if (is_string($this->source) && strpos(" ", $this->source) === false) {
//tablename
$this->type = "query";
$this->query = $this->table($this->source);
} elseif (is_a($this->source, "\\Illuminate\\Database\\Eloquent\\Model")) {
$this->type = "model";
$this->query = $this->source;
$this->key = $this->source->getKeyName();
} elseif (is_a($this->source, "\\Illuminate\\Database\\Eloquent\\Builder")) {
$this->type = "model";
$this->query = $this->source;
$this->key = $this->source->getModel()->getKeyName();
} elseif (is_a($this->source, "\\Illuminate\\Database\\Query\\Builder")) {
$this->type = "model";
$this->query = $this->source;
} elseif (is_a($this->source, "\\Zofe\\Rapyd\\DataFilter\\DataFilter")) {
$this->type = "model";
$this->query = $this->source->query;
if (is_a($this->query, "\\Illuminate\\Database\\Eloquent\\Model")) {
$this->key = $this->query->getKeyName();
} elseif (is_a($this->query, "\\Illuminate\\Database\\Eloquent\\Builder")) {
$this->key = $this->query->getModel()->getKeyName();
}
} elseif (is_array($this->source)) {
$this->type = "array";
} else {
throw new DataSetException(' "source" must be a table name, an eloquent model or an eloquent builder. you passed: ' . get_class($this->source));
}
//build orderby urls
$this->orderby_uri_asc = $this->url->remove('page' . $this->cid)->remove('reset' . $this->cid)->append('ord' . $this->cid, "-field-")->get() . $this->hash;
$this->orderby_uri_desc = $this->url->remove('page' . $this->cid)->remove('reset' . $this->cid)->append('ord' . $this->cid, "--field-")->get() . $this->hash;
//detect orderby
$orderby = $this->url->value("ord" . $this->cid);
if ($orderby) {
$this->orderby_field = ltrim($orderby, "-");
$this->orderby_direction = $orderby[0] === "-" ? "desc" : "asc";
if ($this->canOrderby($this->orderby_field)) {
$this->orderBy($this->orderby_field, $this->orderby_direction);
}
}
//build subset of data
switch ($this->type) {
case "array":
//orderby
if (isset($this->orderby)) {
list($field, $direction) = $this->orderby;
$column = array();
foreach ($this->source as $key => $row) {
$column[$key] = is_object($row) ? $row->{$field} : $row[$field];
}
if ($direction == "asc") {
array_multisort($column, SORT_ASC, $this->source);
} else {
array_multisort($column, SORT_DESC, $this->source);
}
}
$limit = $this->limit ? $this->limit : 100000;
$current_page = $this->url->value('page' . $this->cid, 0);
$offset = max($current_page - 1, 0) * $limit;
$this->data = array_slice($this->source, $offset, $limit);
$this->paginator = new LengthAwarePaginator($this->data, count($this->source), $limit, $current_page, ['path' => Paginator::resolveCurrentPath(), 'pageName' => "page" . $this->cid]);
break;
case "query":
case "model":
//orderby
if (isset($this->orderby)) {
$this->query = $this->query->orderBy($this->orderby[0], $this->orderby[1]);
}
//limit-offset
if (isset($this->limit)) {
$this->paginator = $this->query->paginate($this->limit, ['*'], 'page' . $this->cid);
$this->data = $this->paginator;
} else {
$this->data = $this->query->get();
}
break;
}
return $this;
}
示例10: paginate
/**
* Get the paginated entries.
*
* @param array $columns
* @return Paginator
*/
public function paginate($perPage = 15, array $columns = ['*'])
{
return (new Decorator())->decorate($this->query->paginate($perPage, $columns));
}
示例11: paginate
/**
* 翻页
* @param int $perPage
* @param string $pageName
* @param int|null $page
* @return static
*/
public function paginate(int $perPage, string $pageName = 'page', int $page = null)
{
$this->original->paginate($perPage, ['*'], $pageName, $page);
return $this;
}
示例12: createPaginator
/**
* 翻页
* @param int $perPage
* @param int|null $page
* @return AbstractPaginator
*/
protected function createPaginator(int $perPage, int $page = null) : AbstractPaginator
{
return $this->original->paginate($perPage, ['*'], 'page', $page);
}
示例13: paginate
/**
* Paginate the given query into a simple paginator.
*
* @param int $perPage count of list
* @param array $columns get columns
* @param string $pageName page parameter name
* @param int|null $page page number
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
*/
public function paginate($perPage = 15, $columns = ['*'], $pageName = 'page', $page = null)
{
if ($this->dynamic === false) {
parent::paginate($perPage, $columns);
}
if ($this->proxy === true) {
$this->getProxyManager()->get($this);
}
return parent::paginate($perPage, $columns);
}