-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Revert "🧹 Remove `bakeryPaginate` workaround (#128)" This reverts commit 23dc13f. * Ignore macros directory from analysis
- Loading branch information
1 parent
c91f880
commit b76bf3d
Showing
4 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
use Illuminate\Pagination\Paginator; | ||
use Illuminate\Database\Eloquent\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 | ||
*/ | ||
Builder::macro('bakeryPaginate', function ($perPage = null, $columns = ['*'], $pageName = 'page', $page = null) { | ||
$page = $page ?: Paginator::resolveCurrentPage($pageName); | ||
|
||
$perPage = $perPage ?: $this->model->getPerPage(); | ||
|
||
$countColumns = $this->query->distinct ? [$this->model->getQualifiedKeyName()] : ['*']; | ||
|
||
$results = ($total = $this->toBase()->getCountForPagination($countColumns)) | ||
? $this->forPage($page, $perPage)->get($columns) | ||
: $this->model->newCollection(); | ||
|
||
return $this->paginator($results, $total, $perPage, $page, [ | ||
'path' => Paginator::resolveCurrentPath(), | ||
'pageName' => $pageName, | ||
]); | ||
}); |