Skip to content
This repository was archived by the owner on Oct 20, 2025. It is now read-only.

Commit dfec4c8

Browse files
committed
Update SpladeQueryBuilder.php
1 parent 7c1534c commit dfec4c8

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/SpladeQueryBuilder.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,31 @@ private function loadResults()
318318
// The 'perPage' value is taken from the request query
319319
// string, or from the configured parameter, or it's
320320
// the first from the 'perPage' selector options.
321-
$perPage = $this->query('perPage', $this->perPage ?: Arr::first($this->perPageOptions));
321+
$defaultPerPage = $this->perPage ?: Arr::first($this->perPageOptions);
322+
323+
$perPage = $this->query('perPage', $defaultPerPage);
324+
325+
if (!in_array($perPage, $this->perPageOptions)) {
326+
// The 'perPage' value is not in the allowed options.
327+
// So we'll use the first option.
328+
$perPage = $defaultPerPage;
329+
}
322330

323331
$this->resource = $this->builder->{$this->paginateMethod}($perPage)->withQueryString();
324332
}
325333

334+
/**
335+
* Adds the given 'perPage' value to the 'perPageOptions' array.
336+
*
337+
* @return void
338+
*/
339+
public function addCurrentPerPageValueToOptions()
340+
{
341+
if ($this->perPage && !in_array($this->perPage, $this->perPageOptions)) {
342+
$this->perPageOptions[] = $this->perPage;
343+
}
344+
}
345+
326346
/**
327347
* Prepares the query and loads the results.
328348
*
@@ -334,6 +354,7 @@ public function beforeRender()
334354
$this->applyFilters();
335355
$this->applySearchInputs();
336356
$this->applySortingAndEagerLoading();
357+
$this->addCurrentPerPageValueToOptions();
337358
}
338359

339360
$this->loadResults();

0 commit comments

Comments
 (0)