From 8c5d9baeb7928b16eb28fd80ce469199057bd3df Mon Sep 17 00:00:00 2001 From: Alan Gonzaga Date: Mon, 2 Oct 2023 14:13:27 -0300 Subject: [PATCH 1/3] implement 'IN' Filter --- src/Filter.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Filter.php b/src/Filter.php index c94af9e..40eafe0 100644 --- a/src/Filter.php +++ b/src/Filter.php @@ -180,7 +180,11 @@ private function applyWhere(Builder &$q, string $field, ?bool $or = false) } break; case self::IN: - //TODO: Implement + if ($or) { + $q->orWhereIn($field, $this->value); + } else { + $q->whereIn($field, $this->value); + } break; case self::LESS_THAN: if ($or) { From c0bed948c29f94867f3d976bca5e240e2203b235 Mon Sep 17 00:00:00 2001 From: Alan Gonzaga Date: Mon, 2 Oct 2023 14:17:21 -0300 Subject: [PATCH 2/3] Correcting 'NOT_CONTAINS' filter --- src/Filter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Filter.php b/src/Filter.php index 40eafe0..e4781e3 100644 --- a/src/Filter.php +++ b/src/Filter.php @@ -114,14 +114,14 @@ private function applyWhere(Builder &$q, string $field, ?bool $or = false) case self::NOT_CONTAINS: if ($or) { if(!$jsonField) { - $q->orWhere($field, "NOT" . $this->likeOperator, "%" . $this->value . "%"); + $q->orWhere($field, "NOT " . $this->likeOperator, "%" . $this->value . "%"); } else { $q->orWhereRaw('LOWER('.$jsonField[0].'->>"$.'.$jsonField[1].'") NOT '.$this->likeOperator.' ?', mb_strtolower("%" . $this->value . "%")); } } else { if(!$jsonField) { - $q->where($field, "NOT" . $this->likeOperator, "%" . $this->value . "%"); + $q->where($field, "NOT " . $this->likeOperator, "%" . $this->value . "%"); } else { $q->whereRaw('LOWER('.$jsonField[0].'->>"$.'.$jsonField[1].'") NOT '.$this->likeOperator.' ?', mb_strtolower("%" . $this->value . "%")); From 694f84f1e9c9847d14a68754361690080ab73d35 Mon Sep 17 00:00:00 2001 From: Alan Gonzaga Date: Mon, 2 Oct 2023 23:13:57 -0300 Subject: [PATCH 3/3] Update Filter.php --- src/Filter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Filter.php b/src/Filter.php index e4781e3..552085e 100644 --- a/src/Filter.php +++ b/src/Filter.php @@ -25,7 +25,7 @@ class Filter private $likeOperator = 'LIKE'; - public function __construct(public string $field, public ?string $value = null, public ?string $matchMode = self::CONTAINS) + public function __construct(public string $field, public $value = null, public ?string $matchMode = self::CONTAINS) { $this->likeOperator = \DB::connection()->getPDO()->getAttribute(\PDO::ATTR_DRIVER_NAME) == 'pgsql' ? 'ILIKE' : 'LIKE'; }