Skip to content

Commit 0dcaabc

Browse files
authored
Unify the Implementation of when and unless methods in \Hyperf\Scout\Builder (#6856)
1 parent ddcf756 commit 0dcaabc

File tree

2 files changed

+3
-20
lines changed

2 files changed

+3
-20
lines changed

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"require": {
1111
"php": ">=8.1",
1212
"hyperf/command": "~3.1.0",
13+
"hyperf/conditionable": "~3.1.0",
1314
"hyperf/contract": "~3.1.0",
1415
"hyperf/database": "~3.1.0",
1516
"hyperf/event": "~3.1.0",

src/Builder.php

+2-20
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use Closure;
1616
use Hyperf\Collection\Collection as BaseCollection;
17+
use Hyperf\Conditionable\Conditionable;
1718
use Hyperf\Database\Model\Collection;
1819
use Hyperf\Database\Model\Model;
1920
use Hyperf\Macroable\Macroable;
@@ -26,6 +27,7 @@
2627
class Builder
2728
{
2829
use Macroable;
30+
use Conditionable;
2931

3032
/**
3133
* Optional callback before model query execution.
@@ -127,26 +129,6 @@ public function orderBy(string $column, ?string $direction = 'asc'): static
127129
return $this;
128130
}
129131

130-
/**
131-
* Apply the callback's query changes if the given "value" is true.
132-
*
133-
* @param callable($this, $value): $this $callback
134-
* @param callable($this, $value): $this $default
135-
* @return $this
136-
*/
137-
public function when(mixed $value, callable $callback, ?callable $default = null): static
138-
{
139-
$value = $value instanceof Closure ? $value($this) : $value;
140-
141-
if ($value) {
142-
return $callback($this, $value) ?: $this;
143-
}
144-
if ($default) {
145-
return $default($this, $value) ?: $this;
146-
}
147-
return $this;
148-
}
149-
150132
/**
151133
* Pass the query to a given callback.
152134
*/

0 commit comments

Comments
 (0)