Skip to content

Commit

Permalink
Repace when and tap functions with Conditionable and Tappable traits (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ncharalampidis authored Mar 13, 2024
1 parent f67494a commit 56f40d9
Showing 1 changed file with 3 additions and 31 deletions.
34 changes: 3 additions & 31 deletions src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 56f40d9

Please sign in to comment.