Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: laravel/framework
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 09cc149e94327bfa2fc1376489de76eb6e1b07bc
Choose a base ref
..
head repository: laravel/framework
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 74d94cea8e272169899c1502f61368d87d002523
Choose a head ref
Showing with 33 additions and 9 deletions.
  1. +10 −9 src/Illuminate/Database/Query/Builder.php
  2. +23 −0 tests/Database/DatabaseQueryBuilderTest.php
19 changes: 10 additions & 9 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
@@ -2194,25 +2194,26 @@ public function dynamicWhere($method, $parameters)
*/
public function dynamicWhereColumns($matches, $parameters)
{
$whereColumnsClause = $matches[3];
$boolean = (strtolower($matches[1]) === 'or') ? 'or' : 'and';
// The whereType can be "all", "any", or "none".
$whereType = strtolower($matches[3]);

// If the type is whereNone, then we need to negate the nested where clause
if ($whereColumnsClause === 'None') {
// We determine which boolean type to apply on the nested query.
$boolean = (strtolower($matches[1]) === 'or') ? 'or' : 'and';
if ($whereType === '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)) {
// Next, we determine which where method to apply on the provided columns.
$whereMethod = Str::start($matches[4], $whereType === 'all' ? 'where' : 'orWhere');
if (! method_exists($this, $whereMethod)) {
static::throwBadMethodCallException($matches[0]);
}

$this->whereNested(function ($query) use ($parameters, $whereClause) {
$this->whereNested(function ($query) use ($parameters, $whereMethod) {
// 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) {
$query->{$whereClause}($column, ...$parameters);
$query->{$whereMethod}($column, ...$parameters);
}
}, $boolean);

23 changes: 23 additions & 0 deletions tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
@@ -1489,6 +1489,29 @@ public function testBuilderThrowsExpectedExceptionWithUndefinedWhereNoneMethod()
$builder->select('*')->from('users')->where('name', 'John')->orWhereNonRandomString(['id']);
}

public function testBuilderCanHandleLowerCaseWhereMethods()
{
$builder = $this->getBuilder();
$builder->select('*')->from('users')->wherealllike(['last_name', 'email'], '%Doe%');
$this->assertSame('select * from "users" where ("last_name" like ? and "email" like ?)', $builder->toSql());
$this->assertEquals(['%Doe%', '%Doe%'], $builder->getBindings());

$builder = $this->getBuilder();
$builder->select('*')->from('users')->where('name', 'John')->whereanylike(['last_name', 'email'], '%Doe%');
$this->assertSame('select * from "users" where "name" = ? and ("last_name" like ? or "email" like ?)', $builder->toSql());
$this->assertEquals(['John', '%Doe%', '%Doe%'], $builder->getBindings());

$builder = $this->getBuilder();
$builder->select('*')->from('users')->where('name', 'John')->orwherealllike(['last_name', 'email'], '%Doe%');
$this->assertSame('select * from "users" where "name" = ? or ("last_name" like ? and "email" like ?)', $builder->toSql());
$this->assertEquals(['John', '%Doe%', '%Doe%'], $builder->getBindings());

$builder = $this->getBuilder();
$builder->select('*')->from('users')->where('name', 'John')->orwherenonelike(['last_name', 'email'], '%Doe%');
$this->assertSame('select * from "users" where "name" = ? or not ("last_name" like ? or "email" like ?)', $builder->toSql());
$this->assertEquals(['John', '%Doe%', '%Doe%'], $builder->getBindings());
}

public function testUnions()
{
$builder = $this->getBuilder();