Illuminate\Database\Eloquent\Builder::paginate PHP Method

paginate() public method

Paginate the given query.
public paginate ( integer $perPage = null, array $columns = ['*'], string $pageName = 'page', integer | null $page = null ) : Illuminate\Contracts\Pagination\LengthAwarePaginator
$perPage integer
$columns array
$pageName string
$page integer | null
return Illuminate\Contracts\Pagination\LengthAwarePaginator
    public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
    {
        $page = $page ?: Paginator::resolveCurrentPage($pageName);
        $perPage = $perPage ?: $this->model->getPerPage();
        $query = $this->toBase();
        $total = $query->getCountForPagination();
        $results = $total ? $this->forPage($page, $perPage)->get($columns) : $this->model->newCollection();
        return new LengthAwarePaginator($results, $total, $perPage, $page, ['path' => Paginator::resolveCurrentPath(), 'pageName' => $pageName]);
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Get paginated list
  *
  * @param int $perPage
  * @param array $columns
  * @return mixed
  */
 public function paginate($perPage = 15, $columns = ['*'])
 {
     $this->newQuery()->eagerLoad()->setClauses()->setScopes();
     $models = $this->query->paginate($perPage, $columns);
     $this->unsetClauses();
     return $models;
 }
All Usage Examples Of Illuminate\Database\Eloquent\Builder::paginate