Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
einar-hansen committed Jul 25, 2024
1 parent 2a381e7 commit 09cc149
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2198,17 +2198,17 @@ public function dynamicWhereColumns($matches, $parameters)
$boolean = (strtolower($matches[1]) === 'or') ? 'or' : 'and';

// If the type is whereNone, then we need to negate the nested where clause
if($whereColumnsClause === 'None'){
if ($whereColumnsClause === 'None') {
$boolean .= ' not';
}

// We determine the where clause that should be used on all the columns
$whereClause = Str::start($matches[4], $whereColumnsClause === 'All' ? 'where' : 'orWhere');
if(!method_exists($this,$whereClause)){
if (! method_exists($this, $whereClause)) {
static::throwBadMethodCallException($matches[0]);
}

$this->whereNested(function ($query) use ($parameters, $whereClause, $matches) {
$this->whereNested(function ($query) use ($parameters, $whereClause) {
// We extract the columns, so that we are left with one array containing the columns, and one holding the parameters
$columns = (array) array_shift($parameters);
foreach ($columns as $column) {
Expand Down Expand Up @@ -4394,7 +4394,7 @@ public function __call($method, $parameters)

$pattern = '/^(or)?(Where)(Any|All|None)(.+)$/i';
if (preg_match($pattern, $method, $matches) === 1) {
return $this->dynamicWhereColumns($matches, $parameters );
return $this->dynamicWhereColumns($matches, $parameters);
}

if (str_starts_with($method, 'where')) {
Expand Down
5 changes: 2 additions & 3 deletions tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@ public function testDynamicWhereAll()
$this->assertEquals([100, 200, 100, 200], $builder->getBindings());

$builder = $this->getBuilder();
$builder->select('*')->from('products')->where('name', 'like', '%shirt%')->orWhereAllNotBetween(['price', 'discounted_price'], [100, 200]);
$builder->select('*')->from('products')->where('name', 'like', '%shirt%')->orWhereAllNotBetween(['price', 'discounted_price'], [100, 200]);
$this->assertSame('select * from "products" where "name" like ? or ("price" not between ? and ? and "discounted_price" not between ? and ?)', $builder->toSql());
$this->assertEquals(['%shirt%', 100, 200, 100, 200], $builder->getBindings());

Expand Down Expand Up @@ -1425,7 +1425,6 @@ public function testBuilderThrowsExpectedExceptionWithUndefinedWhereAllMethod()

$builder = $this->getBuilder();
$builder->select('*')->from('users')->where('name', 'John')->orWhereAllHelloWorld(['id']);

}

public function testDynamicWhereAny()
Expand Down Expand Up @@ -1474,7 +1473,7 @@ public function testDynamicWhereNone()
$builder = $this->getBuilder();
$builder->select('*')->from('users')->where('name', 'John')->orWhereNoneIn(['id', 'parent_id'], [1, 2, 3]);
$this->assertSame('select * from "users" where "name" = ? or not ("id" in (?, ?, ?) or "parent_id" in (?, ?, ?))', $builder->toSql());
$this->assertEquals(['John', 1,2,3,1,2,3], $builder->getBindings());
$this->assertEquals(['John', 1, 2, 3, 1, 2, 3], $builder->getBindings());

$builder = $this->getBuilder();
$builder->select('*')->from('users')->where('name', 'John')->orWhereNoneNull(['last_name', 'email']);
Expand Down

0 comments on commit 09cc149

Please sign in to comment.