@@ -307,6 +307,17 @@ public function fromRaw($expression, $bindings = [])
307307 return $ this ;
308308 }
309309
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+
310321 /**
311322 * Creates a subquery and parse it.
312323 *
@@ -698,7 +709,7 @@ public function where($column, $operator = null, $value = null, $boolean = 'and'
698709 );
699710
700711 if (! $ value instanceof Expression) {
701- $ this ->addBinding (is_array ( $ value ) ? head ($ value ) : $ value , 'where ' );
712+ $ this ->addBinding ($ this -> scalarValue ($ value ), 'where ' );
702713 }
703714
704715 return $ this ;
@@ -1043,7 +1054,7 @@ public function whereBetween($column, array $values, $boolean = 'and', $not = fa
10431054
10441055 $ this ->wheres [] = compact ('type ' , 'column ' , 'values ' , 'boolean ' , 'not ' );
10451056
1046- $ this ->addBinding (array_slice ($ this ->cleanBindings ($ values ), 0 , 2 ), 'where ' );
1057+ $ this ->addBinding (array_slice ($ this ->cleanBindings (Arr:: flatten ( $ values) ), 0 , 2 ), 'where ' );
10471058
10481059 return $ this ;
10491060 }
@@ -1111,7 +1122,7 @@ public function whereDate($column, $operator, $value = null, $boolean = 'and')
11111122 $ value , $ operator , func_num_args () === 2
11121123 );
11131124
1114- $ value = is_array ( $ value ) ? head ($ value ) : $ value ;
1125+ $ value = $ this -> scalarValue ($ value );
11151126
11161127 if ($ value instanceof DateTimeInterface) {
11171128 $ value = $ value ->format ('Y-m-d ' );
@@ -1152,7 +1163,7 @@ public function whereTime($column, $operator, $value = null, $boolean = 'and')
11521163 $ value , $ operator , func_num_args () === 2
11531164 );
11541165
1155- $ value = is_array ( $ value ) ? head ($ value ) : $ value ;
1166+ $ value = $ this -> scalarValue ($ value );
11561167
11571168 if ($ value instanceof DateTimeInterface) {
11581169 $ value = $ value ->format ('H:i:s ' );
@@ -1238,7 +1249,7 @@ public function whereMonth($column, $operator, $value = null, $boolean = 'and')
12381249 $ value , $ operator , func_num_args () === 2
12391250 );
12401251
1241- $ value = is_array ( $ value ) ? head ($ value ) : $ value ;
1252+ $ value = $ this -> scalarValue ($ value );
12421253
12431254 if ($ value instanceof DateTimeInterface) {
12441255 $ value = $ value ->format ('m ' );
@@ -1593,7 +1604,7 @@ public function whereJsonLength($column, $operator, $value = null, $boolean = 'a
15931604 $ this ->wheres [] = compact ('type ' , 'column ' , 'operator ' , 'value ' , 'boolean ' );
15941605
15951606 if (! $ value instanceof Expression) {
1596- $ this ->addBinding ((int ) $ value );
1607+ $ this ->addBinding ((int ) $ this -> scalarValue ( $ value) );
15971608 }
15981609
15991610 return $ this ;
@@ -1742,7 +1753,7 @@ public function having($column, $operator = null, $value = null, $boolean = 'and
17421753 $ this ->havings [] = compact ('type ' , 'column ' , 'operator ' , 'value ' , 'boolean ' );
17431754
17441755 if (! $ value instanceof Expression) {
1745- $ this ->addBinding (is_array ( $ value ) ? head ($ value ) : $ value , 'having ' );
1756+ $ this ->addBinding ($ this -> scalarValue ($ value ), 'having ' );
17461757 }
17471758
17481759 return $ this ;
0 commit comments