Skip to content

Commit

Permalink
feat: add handy where helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
kauffinger committed Nov 28, 2024
1 parent 624ff98 commit 0f4637e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
30 changes: 30 additions & 0 deletions src/Query/Concerns/NonFilterable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 0f4637e

Please sign in to comment.