Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -919,9 +919,10 @@ public function where($column, $operator = null, $value = null, $boolean = 'and'
* @param array $column
* @param string $boolean
* @param string $method
* @param string|null $outerBoolean
* @return $this
*/
protected function addArrayOfWheres($column, $boolean, $method = 'where')
protected function addArrayOfWheres($column, $boolean, $method = 'where', $outerBoolean = null)
{
return $this->whereNested(function ($query) use ($column, $method, $boolean) {
foreach ($column as $key => $value) {
Expand All @@ -931,7 +932,7 @@ protected function addArrayOfWheres($column, $boolean, $method = 'where')
$query->{$method}($key, '=', $value, $boolean);
}
}
}, $boolean);
}, $outerBoolean ?? $boolean);
}

/**
Expand Down Expand Up @@ -1004,6 +1005,10 @@ protected function isBitwiseOperator($operator)
*/
public function orWhere($column, $operator = null, $value = null)
{
if (is_array($column)) {
return $this->addArrayOfWheres($column, array_is_list($column) ? 'and' : 'or', outerBoolean: 'or');
}

[$value, $operator] = $this->prepareValueAndOperator(
$value, $operator, func_num_args() === 2
);
Expand Down Expand Up @@ -1041,6 +1046,12 @@ public function whereNot($column, $operator = null, $value = null, $boolean = 'a
*/
public function orWhereNot($column, $operator = null, $value = null)
{
if (is_array($column)) {
return $this->whereNested(function ($query) use ($column, $operator, $value) {
$query->where($column, $operator, $value, array_is_list($column) ? 'and' : 'or');
}, 'or not');
}

return $this->whereNot($column, $operator, $value, 'or');
}

Expand Down Expand Up @@ -1091,6 +1102,10 @@ public function whereColumn($first, $operator = null, $second = null, $boolean =
*/
public function orWhereColumn($first, $operator = null, $second = null)
{
if (is_array($first)) {
return $this->addArrayOfWheres($first, array_is_list($first) ? 'and' : 'or', 'whereColumn', outerBoolean: 'or');
}

return $this->whereColumn($first, $operator, $second, 'or');
}

Expand Down
Loading