From 948c9fc4415dc0ef72afaf8c0eced1b57e0deef3 Mon Sep 17 00:00:00 2001 From: Dwight Watson Date: Mon, 5 Jul 2021 14:41:56 +1000 Subject: [PATCH] Downcase attribute and query for case-insensitive search --- src/Engines/CollectionEngine.php | 2 +- tests/Feature/CollectionEngineTest.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Engines/CollectionEngine.php b/src/Engines/CollectionEngine.php index 72e48cfb..a9c96f27 100644 --- a/src/Engines/CollectionEngine.php +++ b/src/Engines/CollectionEngine.php @@ -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; } } diff --git a/tests/Feature/CollectionEngineTest.php b/tests/Feature/CollectionEngineTest.php index db1fc129..d4cfa2eb 100644 --- a/tests/Feature/CollectionEngineTest.php +++ b/tests/Feature/CollectionEngineTest.php @@ -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);