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

[7.x] Add orWhereIntegerInRaw and orWhereIntegerNotInRaw methods #32710

Merged
merged 2 commits into from
May 7, 2020
Merged
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
24 changes: 24 additions & 0 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,18 @@ public function whereIntegerInRaw($column, $values, $boolean = 'and', $not = fal
return $this;
}

/**
* Add an "or where in raw" clause for integer values to the query.
*
* @param string $column
* @param \Illuminate\Contracts\Support\Arrayable|array $values
* @return $this
*/
public function orWhereIntegerInRaw($column, $values)
{
return $this->whereIntegerInRaw($column, $values, 'or');
}

/**
* Add a "where not in raw" clause for integer values to the query.
*
Expand All @@ -996,6 +1008,18 @@ public function whereIntegerNotInRaw($column, $values, $boolean = 'and')
return $this->whereIntegerInRaw($column, $values, $boolean, true);
}

/**
* Add an "or where not in raw" clause for integer values to the query.
*
* @param string $column
* @param \Illuminate\Contracts\Support\Arrayable|array $values
* @return $this
*/
public function orWhereIntegerNotInRaw($column, $values)
{
return $this->whereIntegerNotInRaw($column, $values, 'or');
}

/**
* Add a "where null" clause to the query.
*
Expand Down
16 changes: 16 additions & 0 deletions tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,14 @@ public function testWhereIntegerInRaw()
$this->assertEquals([], $builder->getBindings());
}

public function testOrWhereIntegerInRaw()
{
$builder = $this->getBuilder();
$builder->select('*')->from('users')->where('id', '=', 1)->orWhereIntegerInRaw('id', ['1a', 2]);
$this->assertSame('select * from "users" where "id" = ? or "id" in (1, 2)', $builder->toSql());
$this->assertEquals([0 => 1], $builder->getBindings());
}

public function testWhereIntegerNotInRaw()
{
$builder = $this->getBuilder();
Expand All @@ -764,6 +772,14 @@ public function testWhereIntegerNotInRaw()
$this->assertEquals([], $builder->getBindings());
}

public function testOrWhereIntegerNotInRaw()
{
$builder = $this->getBuilder();
$builder->select('*')->from('users')->where('id', '=', 1)->orWhereIntegerNotInRaw('id', ['1a', 2]);
$this->assertSame('select * from "users" where "id" = ? or "id" not in (1, 2)', $builder->toSql());
$this->assertEquals([0 => 1], $builder->getBindings());
}

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