From 0f4637ec0d7e2fe6f0b31235193df1737a55d925 Mon Sep 17 00:00:00 2001 From: Konstantin Auffinger Date: Thu, 28 Nov 2024 22:35:11 +0100 Subject: [PATCH] feat: add handy where helpers --- src/Query/Builder.php | 30 ++++++++++++++++++++++++++++ src/Query/Concerns/NonFilterable.php | 30 ++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/src/Query/Builder.php b/src/Query/Builder.php index c818957..d0f609b 100644 --- a/src/Query/Builder.php +++ b/src/Query/Builder.php @@ -370,6 +370,36 @@ public function where(string $column, mixed $operator, mixed $value = null): sta return $this; } + public function whereNot(string $column, mixed $value): static + { + return $this->where($column, '!=', $value); + } + + public function whereIn(string $column, array $values): static + { + return $this->where($column, 'in', $values); + } + + public function whereNotIn(string $column, array $values): static + { + return $this->where($column, 'not in', $values); + } + + public function whereBetween(string $column, int|string $start, int|string $end): static + { + return $this->where($column, 'between', [$start, $end]); + } + + public function whereLike(string $column, string $value): static + { + return $this->where($column, 'like', $value); + } + + public function whereNotLike(string $column, string $value): static + { + return $this->where($column, 'not like', $value); + } + protected function getFilters(): array { return collect($this->filters)->mapWithKeys(function (array $value, string $column) { diff --git a/src/Query/Concerns/NonFilterable.php b/src/Query/Concerns/NonFilterable.php index 1db2ef3..72ccc39 100644 --- a/src/Query/Concerns/NonFilterable.php +++ b/src/Query/Concerns/NonFilterable.php @@ -10,4 +10,34 @@ public function where(string $column, mixed $operator, mixed $value = null): sta { return $this; } + + public function whereNot(string $column, mixed $value): static + { + return $this; + } + + public function whereIn(string $column, array $values): static + { + return $this; + } + + public function whereNotIn(string $column, array $values): static + { + return $this; + } + + public function whereBetween(string $column, int|string $start, int|string $end): static + { + return $this; + } + + public function whereLike(string $column, string $value): static + { + return $this; + } + + public function whereNotLike(string $column, string $value): static + { + return $this; + } }