From 56f40d9467cf082160bc1d6e79d87e1e25a3c860 Mon Sep 17 00:00:00 2001 From: Nikos Charalampidis Date: Wed, 13 Mar 2024 22:55:10 +0200 Subject: [PATCH] Repace when and tap functions with Conditionable and Tappable traits (#811) --- src/Builder.php | 34 +++------------------------------- 1 file changed, 3 insertions(+), 31 deletions(-) diff --git a/src/Builder.php b/src/Builder.php index d8365fd5..c25ed9b9 100644 --- a/src/Builder.php +++ b/src/Builder.php @@ -5,13 +5,15 @@ use Illuminate\Container\Container; use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Pagination\Paginator; +use Illuminate\Support\Traits\Conditionable; use Illuminate\Support\Traits\Macroable; +use Illuminate\Support\Traits\Tappable; use Laravel\Scout\Contracts\PaginatesEloquentModels; use Laravel\Scout\Contracts\PaginatesEloquentModelsUsingDatabase; class Builder { - use Macroable; + use Conditionable, Macroable, Tappable; /** * The model instance. @@ -262,36 +264,6 @@ public function options(array $options) return $this; } - /** - * Apply the callback's query changes if the given "value" is true. - * - * @param mixed $value - * @param callable $callback - * @param callable $default - * @return mixed - */ - public function when($value, $callback, $default = null) - { - if ($value) { - return $callback($this, $value) ?: $this; - } elseif ($default) { - return $default($this, $value) ?: $this; - } - - return $this; - } - - /** - * Pass the query to a given callback. - * - * @param \Closure $callback - * @return $this - */ - public function tap($callback) - { - return $this->when(true, $callback); - } - /** * Set the callback that should have an opportunity to modify the database query. *