Skip to content

[9.x] Iterable value type for whereBetween #36933

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

Merged
merged 2 commits into from
Apr 11, 2021
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
16 changes: 8 additions & 8 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1110,12 +1110,12 @@ public function whereNotNull($columns, $boolean = 'and')
* Add a where between statement to the query.
*
* @param string|\Illuminate\Database\Query\Expression $column
* @param array $values
* @param iterable $values
* @param string $boolean
* @param bool $not
* @return $this
*/
public function whereBetween($column, array $values, $boolean = 'and', $not = false)
public function whereBetween($column, iterable $values, $boolean = 'and', $not = false)
{
$type = 'between';

Expand Down Expand Up @@ -1148,10 +1148,10 @@ public function whereBetweenColumns($column, array $values, $boolean = 'and', $n
* Add an or where between statement to the query.
*
* @param string $column
* @param array $values
* @param iterable $values
* @return $this
*/
public function orWhereBetween($column, array $values)
public function orWhereBetween($column, iterable $values)
{
return $this->whereBetween($column, $values, 'or');
}
Expand All @@ -1172,11 +1172,11 @@ public function orWhereBetweenColumns($column, array $values)
* Add a where not between statement to the query.
*
* @param string $column
* @param array $values
* @param iterable $values
* @param string $boolean
* @return $this
*/
public function whereNotBetween($column, array $values, $boolean = 'and')
public function whereNotBetween($column, iterable $values, $boolean = 'and')
{
return $this->whereBetween($column, $values, $boolean, true);
}
Expand All @@ -1198,10 +1198,10 @@ public function whereNotBetweenColumns($column, array $values, $boolean = 'and')
* Add an or where not between statement to the query.
*
* @param string $column
* @param array $values
* @param iterable $values
* @return $this
*/
public function orWhereNotBetween($column, array $values)
public function orWhereNotBetween($column, iterable $values)
{
return $this->whereNotBetween($column, $values, 'or');
}
Expand Down
11 changes: 11 additions & 0 deletions tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,17 @@ public function testWhereBetweens()
$builder->select('*')->from('users')->whereBetween('id', [new Raw(1), new Raw(2)]);
$this->assertSame('select * from "users" where "id" between 1 and 2', $builder->toSql());
$this->assertEquals([], $builder->getBindings());

$builder = $this->getBuilder();
$period = now()->toPeriod(now()->addDay());
$builder->select('*')->from('users')->whereBetween('created_at', $period);
$this->assertSame('select * from "users" where "created_at" between ? and ?', $builder->toSql());
$this->assertEquals($period->toArray(), $builder->getBindings());

$builder = $this->getBuilder();
$builder->select('*')->from('users')->whereBetween('id', collect([1, 2]));
$this->assertSame('select * from "users" where "id" between ? and ?', $builder->toSql());
$this->assertEquals([0 => 1, 1 => 2], $builder->getBindings());
}

public function testWhereBetweenColumns()
Expand Down