8000 [9.x] Iterable value type for whereBetween (#36933) · laravel/framework@f7cd47a · GitHub
[go: up one dir, main page]

Skip to content

Commit f7cd47a

Browse files
authored
[9.x] Iterable value type for whereBetween (#36933)
* Added CarbonPeriod value type to Query\Builder->whereBetween * Removed CarbonPeriod typehint and replaced it with native iterable type
1 parent c61c862 commit f7cd47a

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/Illuminate/Database/Query/Builder.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,12 +1110,12 @@ public function whereNotNull($columns, $boolean = 'and')
11101110
* Add a where between statement to the query.
11111111
*
11121112
* @param string|\Illuminate\Database\Query\Expression $column
1113-
* @param array $values
1113+
* @param iterable $values
11141114
* @param string $boolean
11151115
* @param bool $not
11161116
* @return $this
11171117
*/
1118-
public function whereBetween($column, array $values, $boolean = 'and', $not = false)
1118+
public function whereBetween($column, iterable $values, $boolean = 'and', $not = false)
11191119
{
11201120
$type = 'between';
11211121

@@ -1148,10 +1148,10 @@ public function whereBetweenColumns($column, array $values, $boolean = 'and', $n
11481148
* Add an or where between statement to the query.
11491149
*
11501150
* @param string $column
1151-
* @param array $values
1151+
* @param iterable $values
11521152
* @return $this
11531153
*/
1154-
public function orWhereBetween($column, array $values)
1154+
public function orWhereBetween($column, iterable $values)
11551155
{
11561156
return $this->whereBetween($column, $values, 'or');
11571157
}
@@ -1172,11 +1172,11 @@ public function orWhereBetweenColumns($column, array $values)
11721172
* Add a where not between statement to the query.
11731173
*
11741174
* @param string $column
1175-
* @param array $values
1175+
* @param iterable $values
11761176
* @param string $boolean
11771177
* @return $this
11781178
*/
1179-
public function whereNotBetween($column, array $values, $boolean = 'and')
1179+
public function whereNotBetween($column, iterable $values, $boolean = 'and')
11801180
{
11811181
return $this->whereBetween($column, $values, $boolean, true);
11821182
}
@@ -1198,10 +1198,10 @@ public function whereNotBetweenColumns($column, array $values, $boolean = 'and')
11981198
* Add an or where not between statement to the query.
11991199
*
12001200
* @param string $column
1201-
* @param array $values
1201+
* @param iterable $values
12021202
* @return $this
12031203
*/
1204-
public function orWhereNotBetween($column, array $values)
1204+
public function orWhereNotBetween($column, iterable $values)
12051205
{
12061206
return $this->whereNotBetween($column, $values, 'or');
12071207
}

tests/Database/DatabaseQueryBuilderTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,17 @@ public function testWhereBetweens()
673673
$builder->select('*')->from('users')->whereBetween('id', [new Raw(1), new Raw(2)]);
674674
$this->assertSame('select * from "users" where "id" between 1 and 2', $builder->toSql());
675675
$this->assertEquals([], $builder->getBindings());
676+
677+
$builder = $this->getBuilder();
678+
$period = now()->toPeriod(now()->addDay());
679+
$builder->select('*')->from('users')->whereBetween('created_at', $period);
680+
$this->assertSame('select * from "users" where "created_at" between ? and ?', $builder->toSql());
681+
$this->assertEquals($period->toArray(), $builder->getBindings());
682+
683+
$builder = $this->getBuilder();
684+
$builder->select('*')->from('users')->whereBetween('id', collect([1, 2]));
685+
$this->assertSame('select * from "users" where "id" between ? and ?', $builder->toSql());
686+
$this->assertEquals([0 => 1, 1 => 2], $builder->getBindings());
676687
}
677688

678689
public function testWhereBetweenColumns()

0 commit comments

Comments
 (0)
0