mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-21 05:20:26 +08:00
CanFilterRecords: check if we have a default filter when no filter is selected, and apply that filter
This commit is contained in:
@@ -26,11 +26,19 @@ trait CanFilterRecords
|
||||
|
||||
protected function applyFilters($query)
|
||||
{
|
||||
if (
|
||||
! $this->isFilterable() ||
|
||||
$this->filter === '' ||
|
||||
$this->filter === null
|
||||
if (! $this->isFilterable()) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
// Check if we have a default filter when no filter is selected
|
||||
if (($this->filter === '' || $this->filter === null) &&
|
||||
($defaultFilter = $this->getTable()->getDefaultFilter())
|
||||
) {
|
||||
$this->filter = $defaultFilter->getName();
|
||||
}
|
||||
|
||||
// We don't have any filter selected and no default one
|
||||
if ($this->filter === '' || $this->filter === null) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user