Skip to content

Commit aa8482d

Browse files
committed
Trim search term when processing
1 parent c1280ec commit aa8482d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/TableComponent.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,15 @@ public function models(): Builder
115115
foreach ($this->columns() as $column) {
116116
if ($column->searchable) {
117117
if (is_callable($column->searchCallback)) {
118-
$builder = app()->call($column->searchCallback, ['builder' => $builder, 'term' => $this->search]);
118+
$builder = app()->call($column->searchCallback, ['builder' => $builder, 'term' => trim($this->search)]);
119119
} elseif (Str::contains($column->attribute, '.')) {
120120
$relationship = $this->relationship($column->attribute);
121121

122122
$builder->orWhereHas($relationship->name, function (Builder $builder) use ($relationship) {
123-
$builder->where($relationship->attribute, 'like', '%'.$this->search.'%');
123+
$builder->where($relationship->attribute, 'like', '%'.trim($this->search).'%');
124124
});
125125
} else {
126-
$builder->orWhere($builder->getModel()->getTable().'.'.$column->attribute, 'like', '%'.$this->search.'%');
126+
$builder->orWhere($builder->getModel()->getTable().'.'.$column->attribute, 'like', '%'.trim($this->search).'%');
127127
}
128128
}
129129
}

0 commit comments

Comments
 (0)