Skip to content

Commit

Permalink
Added $total parameter to pagination.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebronner authored Mar 9, 2023
2 parents 64b6457 + 43de540 commit 1fe3774
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Traits/Buildable.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ public function paginate(
$perPage = null,
$columns = ["*"],
$pageName = "page",
$page = null
$page = null,
$total = null
) {
if (! $this->isCachable()) {
return parent::paginate($perPage, $columns, $pageName, $page);
Expand All @@ -169,8 +170,18 @@ public function paginate(
if (is_array($page)) {
$page = $this->recursiveImplodeWithKey($page);
}

$columns = collect($columns)->toArray();
$cacheKey = $this->makeCacheKey($columns, null, "-paginate_by_{$perPage}_{$pageName}_{$page}");
$keyDifferentiator = "-paginate_by_{$perPage}_{$pageName}_{$page}";

if ($total !== null) {
$total = value($total);
$keyDifferentiator .= $total !== null
? "_{$total}"
: "";
}

$cacheKey = $this->makeCacheKey($columns, null, $keyDifferentiator);

return $this->cachedValue(func_get_args(), $cacheKey);
}
Expand Down

0 comments on commit 1fe3774

Please sign in to comment.