Skip to content

Commit 9438a25

Browse files
committed
If the option keys are numeric, cast them back to ints when getting the filter
1 parent a3b5774 commit 9438a25

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/Traits/WithFilters.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,15 @@ public function hasFilter(string $filter): bool
165165
*
166166
* @param string $filter
167167
*
168-
* @return string|null
168+
* @return int|mixed|null
169169
*/
170-
public function getFilter(string $filter): ?string
170+
public function getFilter(string $filter)
171171
{
172-
return $this->hasFilter($filter) ? $this->filters[$filter] : null;
172+
if ($this->hasFilter($filter)) {
173+
return $this->hasIntegerKeys($filter) ? (int)$this->filters[$filter] : $this->filters[$filter];
174+
}
175+
176+
return null;
173177
}
174178

175179
/**
@@ -206,9 +210,22 @@ public function getFilterOptions(string $filter): array
206210
return collect($this->filters()[$filter]->options())
207211
->keys()
208212
->reject(fn ($item) => $item === '' || $item === null)
213+
->values()
209214
->toArray();
210215
}
211216

217+
/**
218+
* Check whether the filter has numeric keys or not
219+
*
220+
* @param string $filter
221+
*
222+
* @return bool
223+
*/
224+
public function hasIntegerKeys(string $filter): bool
225+
{
226+
return is_int($this->getFilterOptions($filter)[0] ?? null);
227+
}
228+
212229
/**
213230
* Collects columns with $searchable = true
214231
*

0 commit comments

Comments
 (0)