@@ -307,6 +307,17 @@ public function fromRaw($expression, $bindings = [])
307
307
return $ this ;
308
308
}
309
309
310
+ /**
311
+ * Returns scalar type value from an unknown type of input.
312
+ *
313
+ * @param mixed $value
314
+ * @return mixed
315
+ */
316
+ protected function scalarValue ($ value )
317
+ {
318
+ return is_array ($ value ) ? head (Arr::flatten ($ value )) : $ value ;
319
+ }
320
+
310
321
/**
311
322
* Creates a subquery and parse it.
312
323
*
@@ -698,7 +709,7 @@ public function where($column, $operator = null, $value = null, $boolean = 'and'
698
709
);
699
710
700
711
if (! $ value instanceof Expression) {
701
- $ this ->addBinding (is_array ( $ value ) ? head ($ value ) : $ value , 'where ' );
712
+ $ this ->addBinding ($ this -> scalarValue ($ value ), 'where ' );
702
713
}
703
714
704
715
return $ this ;
@@ -1043,7 +1054,7 @@ public function whereBetween($column, array $values, $boolean = 'and', $not = fa
1043
1054
1044
1055
$ this ->wheres [] = compact ('type ' , 'column ' , 'values ' , 'boolean ' , 'not ' );
1045
1056
1046
- $ this ->addBinding (array_slice ($ this ->cleanBindings ($ values ), 0 , 2 ), 'where ' );
1057
+ $ this ->addBinding (array_slice ($ this ->cleanBindings (Arr:: flatten ( $ values) ), 0 , 2 ), 'where ' );
1047
1058
1048
1059
return $ this ;
1049
1060
}
@@ -1111,7 +1122,7 @@ public function whereDate($column, $operator, $value = null, $boolean = 'and')
1111
1122
$ value , $ operator , func_num_args () === 2
1112
1123
);
1113
1124
1114
- $ value = is_array ( $ value ) ? head ($ value ) : $ value ;
1125
+ $ value = $ this -> scalarValue ($ value );
1115
1126
1116
1127
if ($ value instanceof DateTimeInterface) {
1117
1128
$ value = $ value ->format ('Y-m-d ' );
@@ -1152,7 +1163,7 @@ public function whereTime($column, $operator, $value = null, $boolean = 'and')
1152
1163
$ value , $ operator , func_num_args () === 2
1153
1164
);
1154
1165
1155
- $ value = is_array ( $ value ) ? head ($ value ) : $ value ;
1166
+ $ value = $ this -> scalarValue ($ value );
1156
1167
1157
1168
if ($ value instanceof DateTimeInterface) {
1158
1169
$ value = $ value ->format ('H:i:s ' );
@@ -1238,7 +1249,7 @@ public function whereMonth($column, $operator, $value = null, $boolean = 'and')
1238
1249
$ value , $ operator , func_num_args () === 2
1239
1250
);
1240
1251
1241
- $ value = is_array ( $ value ) ? head ($ value ) : $ value ;
1252
+ $ value = $ this -> scalarValue ($ value );
1242
1253
1243
1254
if ($ value instanceof DateTimeInterface) {
1244
1255
$ value = $ value ->format ('m ' );
@@ -1593,7 +1604,7 @@ public function whereJsonLength($column, $operator, $value = null, $boolean = 'a
1593
1604
$ this ->wheres [] = compact ('type ' , 'column ' , 'operator ' , 'value ' , 'boolean ' );
1594
1605
1595
1606
if (! $ value instanceof Expression) {
1596
- $ this ->addBinding ((int ) $ value );
1607
+ $ this ->addBinding ((int ) $ this -> scalarValue ( $ value) );
1597
1608
}
1598
1609
1599
1610
return $ this ;
@@ -1742,7 +1753,7 @@ public function having($column, $operator = null, $value = null, $boolean = 'and
1742
1753
$ this ->havings [] = compact ('type ' , 'column ' , 'operator ' , 'value ' , 'boolean ' );
1743
1754
1744
1755
if (! $ value instanceof Expression) {
1745
- $ this ->addBinding (is_array ( $ value ) ? head ($ value ) : $ value , 'having ' );
1756
+ $ this ->addBinding ($ this -> scalarValue ($ value ), 'having ' );
1746
1757
}
1747
1758
1748
1759
return $ this ;
0 commit comments