Skip to content

Commit 1fe3774

Browse files
authored
Added $total parameter to pagination.
2 parents 64b6457 + 43de540 commit 1fe3774

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/Traits/Buildable.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ public function paginate(
158158
$perPage = null,
159159
$columns = ["*"],
160160
$pageName = "page",
161-
$page = null
161+
$page = null,
162+
$total = null
162163
) {
163164
if (! $this->isCachable()) {
164165
return parent::paginate($perPage, $columns, $pageName, $page);
@@ -169,8 +170,18 @@ public function paginate(
169170
if (is_array($page)) {
170171
$page = $this->recursiveImplodeWithKey($page);
171172
}
173+
172174
$columns = collect($columns)->toArray();
173-
$cacheKey = $this->makeCacheKey($columns, null, "-paginate_by_{$perPage}_{$pageName}_{$page}");
175+
$keyDifferentiator = "-paginate_by_{$perPage}_{$pageName}_{$page}";
176+
177+
if ($total !== null) {
178+
$total = value($total);
179+
$keyDifferentiator .= $total !== null
180+
? "_{$total}"
181+
: "";
182+
}
183+
184+
$cacheKey = $this->makeCacheKey($columns, null, $keyDifferentiator);
174185

175186
return $this->cachedValue(func_get_args(), $cacheKey);
176187
}

0 commit comments

Comments
 (0)