From 5620baea8e2caa84bd52b493d547ef7d607151fd Mon Sep 17 00:00:00 2001 From: Alexandr Chernyaev Date: Wed, 27 Nov 2024 03:01:19 +0300 Subject: [PATCH] Use `whereLike` for case-insensitive search --- src/Filters/Types/Like.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Filters/Types/Like.php b/src/Filters/Types/Like.php index 84a92cdc9..0bff20309 100644 --- a/src/Filters/Types/Like.php +++ b/src/Filters/Types/Like.php @@ -6,11 +6,20 @@ use Illuminate\Database\Eloquent\Builder; use Orchid\Filters\BaseHttpEloquentFilter; +use Composer\InstalledVersions; +use Composer\Semver\VersionParser; class Like extends BaseHttpEloquentFilter { public function run(Builder $builder): Builder { - return $builder->where($this->column, 'like', '%'.$this->getHttpValue().'%'); + if (InstalledVersions::satisfies(new VersionParser, 'laravel/framework', '>11.17.0')) { + return $builder->whereLike($this->column, $this->getHttpValue()); + } + + /** + * @deprecated logic for older Laravel versions + */ + return $builder->where($this->column, 'like', '%' . $this->getHttpValue() . '%'); } }