@@ -993,6 +993,7 @@ protected function compileWhereAll(array $where)
993
993
protected function compileWhereBasic (array $ where )
994
994
{
995
995
extract ($ where );
996
+ $ is_numeric = false ;
996
997
997
998
// Replace like or not like with a Regex instance.
998
999
if (in_array ($ operator , ['like ' , 'not like ' ])) {
@@ -1004,15 +1005,21 @@ protected function compileWhereBasic(array $where)
1004
1005
1005
1006
// Convert to regular expression.
1006
1007
$ regex = preg_replace ('#(^|[^ \\\])%# ' , '$1.* ' , preg_quote ($ value ));
1008
+ $ plain_value = $ value ;
1007
1009
1008
1010
// Convert like to regular expression.
1009
1011
if (!Str::startsWith ($ value , '% ' )) {
1010
1012
$ regex = '^ ' . $ regex ;
1013
+ } else {
1014
+ $ plain_value = Str::replaceFirst ('% ' , null , $ plain_value );
1011
1015
}
1012
1016
if (!Str::endsWith ($ value , '% ' )) {
1013
1017
$ regex .= '$ ' ;
1018
+ } else {
1019
+ $ plain_value = Str::replaceLast ('% ' , null , $ plain_value );
1014
1020
}
1015
1021
1022
+ $ is_numeric = is_numeric ($ plain_value );
1016
1023
$ value = new Regex ($ regex , 'i ' );
1017
1024
} // Manipulate regexp operations.
1018
1025
elseif (in_array ($ operator , ['regexp ' , 'not regexp ' , 'regex ' , 'not regex ' ])) {
@@ -1032,7 +1039,11 @@ protected function compileWhereBasic(array $where)
1032
1039
}
1033
1040
1034
1041
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
+ }
1036
1047
} elseif (array_key_exists ($ operator , $ this ->conversion )) {
1037
1048
$ query = [$ column => [$ this ->conversion [$ operator ] => $ value ]];
1038
1049
} else {
0 commit comments