Skip to content

Commit d62e92d

Browse files
authored
Ensure where with array respects boolean (#53147)
1 parent 11355a4 commit d62e92d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Illuminate/Database/Query/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ protected function addArrayOfWheres($column, $boolean, $method = 'where')
926926
return $this->whereNested(function ($query) use ($column, $method, $boolean) {
927927
foreach ($column as $key => $value) {
928928
if (is_numeric($key) && is_array($value)) {
929-
$query->{$method}(...array_values($value));
929+
$query->{$method}(...array_values($value), boolean: $boolean);
930930
} else {
931931
$query->{$method}($key, '=', $value, $boolean);
932932
}

tests/Database/DatabaseQueryBuilderTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2323,15 +2323,30 @@ public function testWhereWithArrayConditions()
23232323
$this->assertSame('select * from "users" where ("foo" = ? and "bar" = ?)', $builder->toSql());
23242324
$this->assertEquals([0 => 1, 1 => 2], $builder->getBindings());
23252325

2326+
$builder = $this->getBuilder();
2327+
$builder->select('*')->from('users')->where([['foo', 1], ['bar', 2]], boolean: 'or');
2328+
$this->assertSame('select * from "users" where ("foo" = ? or "bar" = ?)', $builder->toSql());
2329+
$this->assertEquals([0 => 1, 1 => 2], $builder->getBindings());
2330+
23262331
$builder = $this->getBuilder();
23272332
$builder->select('*')->from('users')->where(['foo' => 1, 'bar' => 2]);
23282333
$this->assertSame('select * from "users" where ("foo" = ? and "bar" = ?)', $builder->toSql());
23292334
$this->assertEquals([0 => 1, 1 => 2], $builder->getBindings());
23302335

2336+
$builder = $this->getBuilder();
2337+
$builder->select('*')->from('users')->where(['foo' => 1, 'bar' => 2], boolean: 'or');
2338+
$this->assertSame('select * from "users" where ("foo" = ? or "bar" = ?)', $builder->toSql());
2339+
$this->assertEquals([0 => 1, 1 => 2], $builder->getBindings());
2340+
23312341
$builder = $this->getBuilder();
23322342
$builder->select('*')->from('users')->where([['foo', 1], ['bar', '<', 2]]);
23332343
$this->assertSame('select * from "users" where ("foo" = ? and "bar" < ?)', $builder->toSql());
23342344
$this->assertEquals([0 => 1, 1 => 2], $builder->getBindings());
2345+
2346+
$builder = $this->getBuilder();
2347+
$builder->select('*')->from('users')->where([['foo', 1], ['bar', '<', 2]], boolean: 'or');
2348+
$this->assertSame('select * from "users" where ("foo" = ? or "bar" < ?)', $builder->toSql());
2349+
$this->assertEquals([0 => 1, 1 => 2], $builder->getBindings());
23352350
}
23362351

23372352
public function testNestedWheres()

0 commit comments

Comments
 (0)