@@ -672,34 +672,35 @@ protected function whereHaving(string $qbKey, $key, $value = null, string $type
672
672
673
673
$ op = trim (current ($ op ));
674
674
675
- if (substr ($ k , -1 * strlen ($ op )) === $ op ) {
676
- $ k = rtrim (strrev (preg_replace (strrev ('/ ' . $ op . '/ ' ), strrev ('' ), strrev ($ k ), 1 )));
675
+ if (substr ($ k , -strlen ($ op )) === $ op ) {
676
+ $ k = rtrim (substr ($ k , 0 , -strlen ($ op )));
677
+ $ op = " {$ op }" ;
678
+ } else {
679
+ $ op = '' ;
677
680
}
678
- }
679
-
680
- $ bind = $ this ->setBind ($ k , $ v , $ escape );
681
-
682
- if (empty ($ op )) {
683
- $ k .= ' = ' ;
684
681
} else {
685
- $ k .= " { $ op }" ;
682
+ $ op = ' = ' ;
686
683
}
687
684
688
685
if ($ v instanceof Closure) {
689
686
$ builder = $ this ->cleanClone ();
690
- $ v = '( ' . str_replace ( "\n" , ' ' , $ v ($ builder )->getCompiledSelect ()) . ') ' ;
687
+ $ v = ' ( ' . strtr ( $ v ($ builder )->getCompiledSelect (), "\n" , ' ' ) . ') ' ;
691
688
} else {
692
- $ v = " : {$ bind }: " ;
689
+ $ bind = $ this ->setBind ($ k , $ v , $ escape );
690
+ $ v = " : {$ bind }: " ;
693
691
}
694
692
} elseif (! $ this ->hasOperator ($ k ) && $ qbKey !== 'QBHaving ' ) {
695
693
// value appears not to have been set, assign the test to IS NULL
696
- $ k . = ' IS NULL ' ;
694
+ $ op = ' IS NULL ' ;
697
695
} elseif (preg_match ('/\s*(!?=|<>|IS(?:\s+NOT)?)\s*$/i ' , $ k , $ match , PREG_OFFSET_CAPTURE )) {
698
- $ k = substr ($ k , 0 , $ match [0 ][1 ]) . ($ match [1 ][0 ] === '= ' ? ' IS NULL ' : ' IS NOT NULL ' );
696
+ $ k = substr ($ k , 0 , $ match [0 ][1 ]);
697
+ $ op = $ match [1 ][0 ] === '= ' ? ' IS NULL ' : ' IS NOT NULL ' ;
698
+ } else {
699
+ $ op = '' ;
699
700
}
700
701
701
702
$ this ->{$ qbKey }[] = [
702
- 'condition ' => $ prefix . $ k . $ v ,
703
+ 'condition ' => $ prefix . $ k . $ op . $ v ,
703
704
'escape ' => $ escape ,
704
705
];
705
706
}
@@ -855,7 +856,7 @@ protected function _whereIn(?string $key = null, $values = null, bool $not = fal
855
856
856
857
if ($ values instanceof Closure) {
857
858
$ builder = $ this ->cleanClone ();
858
- $ ok = str_replace ( "\n" , ' ' , $ values ($ builder )->getCompiledSelect ());
859
+ $ ok = strtr ( $ values ($ builder )->getCompiledSelect (), "\n" , ' ' );
859
860
} else {
860
861
$ whereIn = array_values ($ values );
861
862
$ ok = $ this ->setBind ($ ok , $ whereIn , $ escape );
0 commit comments