Skip to content

Commit

Permalink
Downcase attribute and query for case-insensitive search (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwightwatson authored Jul 5, 2021
1 parent b79a62d commit 8c0b39a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Engines/CollectionEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ protected function searchModels(Builder $builder)
foreach ($columns as $column) {
$attribute = $model->{$column};

if (Str::contains($attribute, $builder->query)) {
if (Str::contains(Str::lower($attribute), Str::lower($builder->query))) {
return true;
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/Feature/CollectionEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public function test_it_can_retrieve_results()
$models = SearchableUserModel::search('Taylor')->where('email', 'taylor@laravel.com')->get();
$this->assertCount(1, $models);

$models = SearchableUserModel::search('otwell')->get();
$this->assertCount(2, $models);

$models = SearchableUserModel::search('laravel')->get();
$this->assertCount(2, $models);

Expand Down

0 comments on commit 8c0b39a

Please sign in to comment.