Skip to content

Commit d7aa542

Browse files
committed
feat: add conditional callback method to QueryBuilder for improved query flexibility
1 parent e4a23b7 commit d7aa542

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/Support/QueryBuilder.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ public function offset(int $offset): static
4747
return $this;
4848
}
4949

50+
/**
51+
* Apply callback conditionally when the given value is truthy
52+
*/
53+
public function when(mixed $value, callable $callback, ?callable $default = null): static
54+
{
55+
if ($value) {
56+
$callback($this, $value);
57+
} elseif ($default) {
58+
$default($this, $value);
59+
}
60+
61+
return $this;
62+
}
63+
5064
/**
5165
* Execute the query and return the results
5266
*/

0 commit comments

Comments
 (0)