@@ -993,6 +993,7 @@ protected function compileWhereAll(array $where)
993993 protected function compileWhereBasic (array $ where )
994994 {
995995 extract ($ where );
996+ $ is_numeric = false ;
996997
997998 // Replace like or not like with a Regex instance.
998999 if (in_array ($ operator , ['like ' , 'not like ' ])) {
@@ -1003,17 +1004,23 @@ protected function compileWhereBasic(array $where)
10031004 }
10041005
10051006 // Convert to regular expression.
1006- $ regex = preg_replace ('#(^|[^ \\\])%# ' , '$1.* ' , preg_quote ($ value ));
1007+ $ regex = preg_replace ('#(^|[^ \\\])%# ' , '$1.* ' , preg_quote ($ value ));
1008+ $ plain_value = $ value ;
10071009
10081010 // Convert like to regular expression.
10091011 if (!Str::startsWith ($ value , '% ' )) {
10101012 $ regex = '^ ' . $ regex ;
1013+ } else {
1014+ $ plain_value = Str::replaceFirst ('% ' , null , $ plain_value );
10111015 }
10121016 if (!Str::endsWith ($ value , '% ' )) {
10131017 $ regex .= '$ ' ;
1018+ } else {
1019+ $ plain_value = Str::replaceLast ('% ' , null , $ plain_value );
10141020 }
10151021
1016- $ value = new Regex ($ regex , 'i ' );
1022+ $ is_numeric = is_numeric ($ plain_value );
1023+ $ value = new Regex ($ regex , 'i ' );
10171024 } // Manipulate regexp operations.
10181025 elseif (in_array ($ operator , ['regexp ' , 'not regexp ' , 'regex ' , 'not regex ' ])) {
10191026 // Automatically convert regular expression strings to Regex objects.
@@ -1032,7 +1039,11 @@ protected function compileWhereBasic(array $where)
10321039 }
10331040
10341041 if (!isset ($ operator ) || $ operator == '= ' ) {
1035- $ query = [$ column => $ value ];
1042+ if ($ is_numeric ) {
1043+ $ query = ['$where ' => '/^ ' .$ value ->getPattern ().'/.test(this. ' .$ column .') ' ];
1044+ } else {
1045+ $ query = [$ column => $ value ];
1046+ }
10361047 } elseif (array_key_exists ($ operator , $ this ->conversion )) {
10371048 $ query = [$ column => [$ this ->conversion [$ operator ] => $ value ]];
10381049 } else {
0 commit comments