Skip to content

Commit 6a70c09

Browse files
committed
add a way to limit query server side
1 parent 648c417 commit 6a70c09

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/app/Http/Controllers/Operations/ListOperation.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ public function search()
7979
$length = (int) request()->input('length');
8080
$search = request()->input('search');
8181

82+
// we get the max length from the page length menu possibilities
83+
$maxLength = $this->crud->maxPageLength();
84+
85+
$length = $maxLength === -1 ? $length : ($length > $maxLength ? $maxLength : $length);
86+
8287
// if a search term was present
8388
if ($search && $search['value'] ?? false) {
8489
// filter the results accordingly

src/app/Library/CrudPanel/Traits/Read.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,21 @@ public function getDefaultPageLength()
218218
return $this->getOperationSetting('defaultPageLength') ?? config('backpack.crud.operations.list.defaultPageLength') ?? 25;
219219
}
220220

221+
/**
222+
* Get the higher limit from the page length menu.
223+
* -1 means "All" so if present it means no limit.
224+
*/
225+
public function maxPageLength(): int
226+
{
227+
$pageLengthMenu = $this->getPageLengthMenu();
228+
229+
if(in_array(-1, $pageLengthMenu[0])) {
230+
return -1;
231+
}
232+
233+
return (int)max($pageLengthMenu[0]);
234+
}
235+
221236
/**
222237
* If a custom page length was specified as default, make sure it
223238
* also show up in the page length menu.

0 commit comments

Comments
 (0)