Skip to content

Commit ddbac6e

Browse files
committed
Extract session key
1 parent ad8eb5f commit ddbac6e

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/Traits/WithPerPagePagination.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public function mountWithPerPagePagination(): void
2020
$this->perPageAccepted[] = -1;
2121
}
2222

23-
if (in_array(session()->get($this->tableName.'-perPage', $this->perPage), $this->perPageAccepted, true)) {
24-
$this->perPage = session()->get($this->tableName.'-perPage', $this->perPage);
23+
if (in_array(session()->get($this->getPerPagePaginationSessionKey(), $this->perPage), $this->perPageAccepted, true)) {
24+
$this->perPage = session()->get($this->getPerPagePaginationSessionKey(), $this->perPage);
2525
} else {
2626
$this->perPage = $this->perPageAccepted[0] ?? 10;
2727
}
@@ -32,10 +32,10 @@ public function mountWithPerPagePagination(): void
3232
*/
3333
public function updatedPerPage($value): void
3434
{
35-
if (in_array(session()->get($this->tableName.'-perPage', $this->perPage), $this->perPageAccepted, true)) {
36-
session()->put($this->tableName.'-perPage', (int) $value);
35+
if (in_array(session()->get($this->getPerPagePaginationSessionKey(), $this->perPage), $this->perPageAccepted, true)) {
36+
session()->put($this->getPerPagePaginationSessionKey(), (int) $value);
3737
} else {
38-
session()->put($this->tableName.'-perPage', $this->perPageAccepted[0] ?? 10);
38+
session()->put($this->getPerPagePaginationSessionKey(), $this->perPageAccepted[0] ?? 10);
3939
}
4040

4141
$this->resetPage();
@@ -49,4 +49,9 @@ public function applyPagination($query)
4949
{
5050
return $query->paginate($this->perPage === -1 ? $query->count() : $this->perPage, ['*'], $this->pageName());
5151
}
52+
53+
private function getPerPagePaginationSessionKey(): string
54+
{
55+
return $this->tableName.'-perPage';
56+
}
5257
}

0 commit comments

Comments
 (0)