Skip to content

Commit 552d37f

Browse files
committed
feat: add new helper methods to the page numbers trait
1 parent 1158d50 commit 552d37f

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

src/Core/Pagination/Concerns/HasPageNumbers.php

+39-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ trait HasPageNumbers
2929
*/
3030
private ?int $defaultPerPage = null;
3131

32+
/**
33+
* @var int
34+
*/
35+
private int $maxPerPage = 0;
36+
37+
/**
38+
* @var bool
39+
*/
40+
private bool $required = false;
41+
3242
/**
3343
* Get the keys expected in the `page` query parameter for this paginator.
3444
*
@@ -48,7 +58,7 @@ public function keys(): array
4858
* @param string $key
4959
* @return $this
5060
*/
51-
public function withPageKey(string $key): self
61+
public function withPageKey(string $key): static
5262
{
5363
$this->pageKey = $key;
5464

@@ -61,7 +71,7 @@ public function withPageKey(string $key): self
6171
* @param string $key
6272
* @return $this
6373
*/
64-
public function withPerPageKey(string $key): self
74+
public function withPerPageKey(string $key): static
6575
{
6676
$this->perPageKey = $key;
6777

@@ -74,11 +84,37 @@ public function withPerPageKey(string $key): self
7484
* @param int|null $perPage
7585
* @return $this
7686
*/
77-
public function withDefaultPerPage(?int $perPage): self
87+
public function withDefaultPerPage(?int $perPage): static
7888
{
7989
$this->defaultPerPage = $perPage;
8090

8191
return $this;
8292
}
8393

94+
/**
95+
* Set the maximum number of records per-page.
96+
*
97+
* @param int $max
98+
* @return $this
99+
*/
100+
public function withMaxPerPage(int $max): static
101+
{
102+
assert($max > 0, 'Expecting max per page to be greater than zero.');
103+
104+
$this->maxPerPage = $max;
105+
106+
return $this;
107+
}
108+
109+
/**
110+
* Force the client to always provided a page number.
111+
*
112+
* @return $this
113+
*/
114+
public function required(): static
115+
{
116+
$this->required = true;
117+
118+
return $this;
119+
}
84120
}

0 commit comments

Comments
 (0)