Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.8] allow whereNull and whereNotNull to accept array columns argument #29154

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
allow whereNull to accept array columns argument
  • Loading branch information
ninjaparade committed Jul 12, 2019
commit 0a3c781525cd61c80d7b95f7f091b0ae2e67c388
8 changes: 5 additions & 3 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -996,16 +996,18 @@ public function whereIntegerNotInRaw($column, $values, $boolean = 'and')
/**
* Add a "where null" clause to the query.
*
* @param string $column
* @param string|array $column
ninjaparade marked this conversation as resolved.
Show resolved Hide resolved
* @param string $boolean
* @param bool $not
* @return $this
*/
public function whereNull($column, $boolean = 'and', $not = false)
public function whereNull($columns, $boolean = 'and', $not = false)
{
$type = $not ? 'NotNull' : 'Null';

$this->wheres[] = compact('type', 'column', 'boolean');
foreach (Arr::wrap($columns) as $column) {
$this->wheres[] = compact('type', 'column', 'boolean');
}

return $this;
}
Expand Down
26 changes: 26 additions & 0 deletions tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,19 @@ public function testBasicWhereNulls()
$this->assertEquals([0 => 1], $builder->getBindings());
}

public function testArrayWhereNulls()
{
$builder = $this->getBuilder();
$builder->select('*')->from('users')->whereNull(['id', 'expires_at']);
$this->assertEquals('select * from "users" where "id" is null and "expires_at" is null', $builder->toSql());
$this->assertEquals([], $builder->getBindings());

$builder = $this->getBuilder();
$builder->select('*')->from('users')->where('id', '=', 1)->orWhereNull(['id', 'expires_at']);
$this->assertEquals('select * from "users" where "id" = ? or "id" is null or "expires_at" is null', $builder->toSql());
$this->assertEquals([0 => 1], $builder->getBindings());
}

public function testBasicWhereNotNulls()
{
$builder = $this->getBuilder();
Expand All @@ -983,6 +996,19 @@ public function testBasicWhereNotNulls()
$this->assertEquals([0 => 1], $builder->getBindings());
}

public function testArrayWhereNotNulls()
{
$builder = $this->getBuilder();
$builder->select('*')->from('users')->whereNotNull(['id', 'expires_at']);
$this->assertEquals('select * from "users" where "id" is not null and "expires_at" is not null', $builder->toSql());
$this->assertEquals([], $builder->getBindings());

$builder = $this->getBuilder();
$builder->select('*')->from('users')->where('id', '>', 1)->orWhereNotNull(['id', 'expires_at']);
$this->assertEquals('select * from "users" where "id" > ? or "id" is not null or "expires_at" is not null', $builder->toSql());
$this->assertEquals([0 => 1], $builder->getBindings());
}

public function testGroupBys()
{
$builder = $this->getBuilder();
Expand Down