123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- namespace App\Base\Models;
- use Illuminate\Database\Eloquent\Builder;
- use Illuminate\Pagination\Paginator;
- /**
- * @mixin \Illuminate\Database\Query\Builder
- */
- class EloquentBuilder extends Builder
- {
- /**
- * Paginate the given query.
- *
- * @param int $perPage
- * @param array $columns
- * @param string $pageName
- * @param int|null $page
- * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
- *
- * @throws \InvalidArgumentException
- */
- public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
- {
- $page = $page ?: Paginator::resolveCurrentPage($pageName);
- $perPage = $perPage ?: $this->model->getPerPage();
- $results = ($total = $this->toBase()->getCountForPagination($columns))
- ? $this->forPage($page, $perPage)->get($columns)
- : $this->model->newCollection();
- return $this->paginator($results, $total, $perPage, $page, [
- 'path' => Paginator::resolveCurrentPath(),
- 'pageName' => $pageName,
- ]);
- }
- }
|