diff --git a/composer.json b/composer.json index a60ec32..062f1b9 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,7 @@ "require": { "php": ">=8.1", "hyperf/command": "~3.1.0", + "hyperf/conditionable": "~3.1.0", "hyperf/contract": "~3.1.0", "hyperf/database": "~3.1.0", "hyperf/event": "~3.1.0", diff --git a/src/Builder.php b/src/Builder.php index 7649554..14cd57a 100644 --- a/src/Builder.php +++ b/src/Builder.php @@ -14,6 +14,7 @@ use Closure; use Hyperf\Collection\Collection as BaseCollection; +use Hyperf\Conditionable\Conditionable; use Hyperf\Database\Model\Collection; use Hyperf\Database\Model\Model; use Hyperf\Macroable\Macroable; @@ -26,6 +27,7 @@ class Builder { use Macroable; + use Conditionable; /** * Optional callback before model query execution. @@ -127,26 +129,6 @@ public function orderBy(string $column, ?string $direction = 'asc'): static return $this; } - /** - * Apply the callback's query changes if the given "value" is true. - * - * @param callable($this, $value): $this $callback - * @param callable($this, $value): $this $default - * @return $this - */ - public function when(mixed $value, callable $callback, ?callable $default = null): static - { - $value = $value instanceof Closure ? $value($this) : $value; - - if ($value) { - return $callback($this, $value) ?: $this; - } - if ($default) { - return $default($this, $value) ?: $this; - } - return $this; - } - /** * Pass the query to a given callback. */