PR #8392 trim in getTableSearch(), preserving a null if present

This commit is contained in:
Jason Judge
2023-09-11 00:00:13 +01:00
parent f569d3dad0
commit 3cafad8b84
2 changed files with 17 additions and 2 deletions
@@ -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());
});