mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
PR #8392 trim in getTableSearch(), preserving a null if present
This commit is contained in:
@@ -113,7 +113,7 @@ trait CanSearchRecords
|
||||
|
||||
protected function applyGlobalSearchToTableQuery(Builder $query): Builder
|
||||
{
|
||||
$search = trim($this->getTableSearch());
|
||||
$search = $this->getTableSearch();
|
||||
|
||||
if (blank($search)) {
|
||||
return $query;
|
||||
@@ -149,7 +149,7 @@ trait CanSearchRecords
|
||||
*/
|
||||
public function getTableSearch()
|
||||
{
|
||||
return $this->tableSearch;
|
||||
return $this->tableSearch === null ? null : trim($this->tableSearch);
|
||||
}
|
||||
|
||||
public function hasTableSearch(): bool
|
||||
|
||||
@@ -33,3 +33,18 @@ it('can split on whitespace', function () {
|
||||
|
||||
$this->assertSame(['', 'test', ''], $trait->extractTableSearchWords(' test '));
|
||||
});
|
||||
|
||||
it('can trim a search query', function () {
|
||||
$trait = new class {
|
||||
use \Filament\Tables\Concerns\CanSearchRecords;
|
||||
};
|
||||
|
||||
$trait->tableSearch = 'test';
|
||||
$this->assertSame('test', $trait->getTableSearch());
|
||||
|
||||
$trait->tableSearch = ' test ';
|
||||
$this->assertSame('test', $trait->getTableSearch());
|
||||
|
||||
$trait->tableSearch = null;
|
||||
$this->assertNull($trait->getTableSearch());
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user