Skip to content

Commit

Permalink
add parameter to eloquent query builder when() (#15442)
Browse files Browse the repository at this point in the history
  • Loading branch information
themsaid authored and taylorotwell committed Sep 15, 2016
1 parent 6cf003a commit 086d492
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -738,14 +738,17 @@ protected function isNested($name, $relation)
*
* @param bool $value
* @param \Closure $callback
* @param \Closure $default
* @return $this
*/
public function when($value, $callback)
public function when($value, $callback, $default = null)
{
$builder = $this;

if ($value) {
$builder = call_user_func($callback, $builder);
} elseif ($default) {
$builder = call_user_func($default, $builder);
}

return $builder;
Expand Down

0 comments on commit 086d492

Please sign in to comment.