@@ -29,6 +29,16 @@ trait HasPageNumbers
29
29
*/
30
30
private ?int $ defaultPerPage = null ;
31
31
32
+ /**
33
+ * @var int
34
+ */
35
+ private int $ maxPerPage = 0 ;
36
+
37
+ /**
38
+ * @var bool
39
+ */
40
+ private bool $ required = false ;
41
+
32
42
/**
33
43
* Get the keys expected in the `page` query parameter for this paginator.
34
44
*
@@ -48,7 +58,7 @@ public function keys(): array
48
58
* @param string $key
49
59
* @return $this
50
60
*/
51
- public function withPageKey (string $ key ): self
61
+ public function withPageKey (string $ key ): static
52
62
{
53
63
$ this ->pageKey = $ key ;
54
64
@@ -61,7 +71,7 @@ public function withPageKey(string $key): self
61
71
* @param string $key
62
72
* @return $this
63
73
*/
64
- public function withPerPageKey (string $ key ): self
74
+ public function withPerPageKey (string $ key ): static
65
75
{
66
76
$ this ->perPageKey = $ key ;
67
77
@@ -74,11 +84,37 @@ public function withPerPageKey(string $key): self
74
84
* @param int|null $perPage
75
85
* @return $this
76
86
*/
77
- public function withDefaultPerPage (?int $ perPage ): self
87
+ public function withDefaultPerPage (?int $ perPage ): static
78
88
{
79
89
$ this ->defaultPerPage = $ perPage ;
80
90
81
91
return $ this ;
82
92
}
83
93
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
+ }
84
120
}
0 commit comments