Skip to content

Commit 2d9b970

Browse files
committed
fix conflicts
2 parents 5d572e7 + c05390b commit 2d9b970

File tree

2 files changed

+47
-12
lines changed

2 files changed

+47
-12
lines changed

src/Illuminate/Database/Query/Builder.php

+21-10
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ public function where($column, $operator = null, $value = null, $boolean = 'and'
752752
);
753753

754754
if (! $value instanceof Expression) {
755-
$this->addBinding(is_array($value) ? head($value) : $value, 'where');
755+
$this->addBinding($this->flattenValue($value), 'where');
756756
}
757757

758758
return $this;
@@ -1121,7 +1121,7 @@ public function whereBetween($column, array $values, $boolean = 'and', $not = fa
11211121

11221122
$this->wheres[] = compact('type', 'column', 'values', 'boolean', 'not');
11231123

1124-
$this->addBinding(array_slice($this->cleanBindings($values), 0, 2), 'where');
1124+
$this->addBinding(array_slice($this->cleanBindings(Arr::flatten($values)), 0, 2), 'where');
11251125

11261126
return $this;
11271127
}
@@ -1244,7 +1244,7 @@ public function whereDate($column, $operator, $value = null, $boolean = 'and')
12441244
$value, $operator, func_num_args() === 2
12451245
);
12461246

1247-
$value = is_array($value) ? head($value) : $value;
1247+
$value = $this->flattenValue($value);
12481248

12491249
if ($value instanceof DateTimeInterface) {
12501250
$value = $value->format('Y-m-d');
@@ -1285,7 +1285,7 @@ public function whereTime($column, $operator, $value = null, $boolean = 'and')
12851285
$value, $operator, func_num_args() === 2
12861286
);
12871287

1288-
$value = is_array($value) ? head($value) : $value;
1288+
$value = $this->flattenValue($value);
12891289

12901290
if ($value instanceof DateTimeInterface) {
12911291
$value = $value->format('H:i:s');
@@ -1326,7 +1326,7 @@ public function whereDay($column, $operator, $value = null, $boolean = 'and')
13261326
$value, $operator, func_num_args() === 2
13271327
);
13281328

1329-
$value = is_array($value) ? head($value) : $value;
1329+
$value = $this->flattenValue($value);
13301330

13311331
if ($value instanceof DateTimeInterface) {
13321332
$value = $value->format('d');
@@ -1371,7 +1371,7 @@ public function whereMonth($column, $operator, $value = null, $boolean = 'and')
13711371
$value, $operator, func_num_args() === 2
13721372
);
13731373

1374-
$value = is_array($value) ? head($value) : $value;
1374+
$value = $this->flattenValue($value);
13751375

13761376
if ($value instanceof DateTimeInterface) {
13771377
$value = $value->format('m');
@@ -1416,7 +1416,7 @@ public function whereYear($column, $operator, $value = null, $boolean = 'and')
14161416
$value, $operator, func_num_args() === 2
14171417
);
14181418

1419-
$value = is_array($value) ? head($value) : $value;
1419+
$value = $this->flattenValue($value);
14201420

14211421
if ($value instanceof DateTimeInterface) {
14221422
$value = $value->format('Y');
@@ -1726,7 +1726,7 @@ public function whereJsonLength($column, $operator, $value = null, $boolean = 'a
17261726
$this->wheres[] = compact('type', 'column', 'operator', 'value', 'boolean');
17271727

17281728
if (! $value instanceof Expression) {
1729-
$this->addBinding((int) $value);
1729+
$this->addBinding((int) $this->flattenValue($value));
17301730
}
17311731

17321732
return $this;
@@ -1875,7 +1875,7 @@ public function having($column, $operator = null, $value = null, $boolean = 'and
18751875
$this->havings[] = compact('type', 'column', 'operator', 'value', 'boolean');
18761876

18771877
if (! $value instanceof Expression) {
1878-
$this->addBinding(is_array($value) ? head($value) : $value, 'having');
1878+
$this->addBinding($this->flattenValue($value), 'having');
18791879
}
18801880

18811881
return $this;
@@ -1913,7 +1913,7 @@ public function havingBetween($column, array $values, $boolean = 'and', $not = f
19131913

19141914
$this->havings[] = compact('type', 'column', 'values', 'boolean', 'not');
19151915

1916-
$this->addBinding($this->cleanBindings($values), 'having');
1916+
$this->addBinding(array_slice($this->cleanBindings(Arr::flatten($values)), 0, 2), 'having');
19171917

19181918
return $this;
19191919
}
@@ -3178,6 +3178,17 @@ public function cleanBindings(array $bindings)
31783178
}));
31793179
}
31803180

3181+
/**
3182+
* Get a scalar type value from an unknown type of input.
3183+
*
3184+
* @param mixed $value
3185+
* @return mixed
3186+
*/
3187+
protected function flattenValue($value)
3188+
{
3189+
return is_array($value) ? head(Arr::flatten($value)) : $value;
3190+
}
3191+
31813192
/**
31823193
* Get the default key name of the table.
31833194
*

tests/Database/DatabaseQueryBuilderTest.php

+26-2
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,11 @@ public function testWheresWithArrayValue()
319319
$builder->select('*')->from('users')->where('id', '<>', [12, 30]);
320320
$this->assertSame('select * from "users" where "id" <> ?', $builder->toSql());
321321
$this->assertEquals([0 => 12], $builder->getBindings());
322+
323+
$builder = $this->getBuilder();
324+
$builder->select('*')->from('users')->where('id', '=', [[12, 30]]);
325+
$this->assertSame('select * from "users" where "id" = ?', $builder->toSql());
326+
$this->assertEquals([0 => 12], $builder->getBindings());
322327
}
323328

324329
public function testMySqlWrappingProtectsQuotationMarks()
@@ -649,6 +654,16 @@ public function testWhereBetweens()
649654
$this->assertSame('select * from "users" where "id" between ? and ?', $builder->toSql());
650655
$this->assertEquals([0 => 1, 1 => 2], $builder->getBindings());
651656

657+
$builder = $this->getBuilder();
658+
$builder->select('*')->from('users')->whereBetween('id', [[1, 2, 3]]);
659+
$this->assertSame('select * from "users" where "id" between ? and ?', $builder->toSql());
660+
$this->assertEquals([0 => 1, 1 => 2], $builder->getBindings());
661+
662+
$builder = $this->getBuilder();
663+
$builder->select('*')->from('users')->whereBetween('id', [[1], [2, 3]]);
664+
$this->assertSame('select * from "users" where "id" between ? and ?', $builder->toSql());
665+
$this->assertEquals([0 => 1, 1 => 2], $builder->getBindings());
666+
652667
$builder = $this->getBuilder();
653668
$builder->select('*')->from('users')->whereNotBetween('id', [1, 2]);
654669
$this->assertSame('select * from "users" where "id" not between ? and ?', $builder->toSql());
@@ -1244,10 +1259,19 @@ public function testHavings()
12441259
$builder = $this->getBuilder();
12451260
$builder->select(['category', new Raw('count(*) as "total"')])->from('item')->where('department', '=', 'popular')->groupBy('category')->having('total', '>', 3);
12461261
$this->assertSame('select "category", count(*) as "total" from "item" where "department" = ? group by "category" having "total" > ?', $builder->toSql());
1262+
}
12471263

1264+
public function testHavingBetweens()
1265+
{
12481266
$builder = $this->getBuilder();
1249-
$builder->select('*')->from('users')->havingBetween('last_login_date', ['2018-11-16', '2018-12-16']);
1250-
$this->assertSame('select * from "users" having "last_login_date" between ? and ?', $builder->toSql());
1267+
$builder->select('*')->from('users')->havingBetween('id', [1, 2, 3]);
1268+
$this->assertSame('select * from "users" having "id" between ? and ?', $builder->toSql());
1269+
$this->assertEquals([0 => 1, 1 => 2], $builder->getBindings());
1270+
1271+
$builder = $this->getBuilder();
1272+
$builder->select('*')->from('users')->havingBetween('id', [[1, 2], [3, 4]]);
1273+
$this->assertSame('select * from "users" having "id" between ? and ?', $builder->toSql());
1274+
$this->assertEquals([0 => 1, 1 => 2], $builder->getBindings());
12511275
}
12521276

12531277
public function testHavingShortcut()

0 commit comments

Comments
 (0)