7
7
use Illuminate \Database \Query \Builder as BaseBuilder ;
8
8
use Illuminate \Database \Query \Expression ;
9
9
use Illuminate \Support \Arr ;
10
+ use Illuminate \Support \Carbon ;
10
11
use Illuminate \Support \Collection ;
11
12
use Illuminate \Support \LazyCollection ;
12
13
use Illuminate \Support \Str ;
@@ -1163,10 +1164,40 @@ protected function compileWhereDate(array $where)
1163
1164
{
1164
1165
extract ($ where );
1165
1166
1166
- $ where ['operator ' ] = $ operator ;
1167
- $ where ['value ' ] = $ value ;
1167
+ $ date = Carbon::parse ($ value );
1168
1168
1169
- return $ this ->compileWhereBasic ($ where );
1169
+ $ operator = $ operator === '= ' ? '$eq ' : $ this ->conversion [$ operator ];
1170
+
1171
+ return [
1172
+ '$expr ' => [
1173
+ '$and ' => [
1174
+ [
1175
+ $ operator => [
1176
+ [
1177
+ '$dayOfMonth ' => '$ ' .$ column
1178
+ ],
1179
+ $ date ->day
1180
+ ],
1181
+ ],
1182
+ [
1183
+ $ operator => [
1184
+ [
1185
+ '$month ' => '$ ' .$ column
1186
+ ],
1187
+ $ date ->month
1188
+ ],
1189
+ ],
1190
+ [
1191
+ $ operator => [
1192
+ [
1193
+ '$month ' => '$ ' .$ column
1194
+ ],
1195
+ $ date ->year
1196
+ ],
1197
+ ],
1198
+ ],
1199
+ ],
1200
+ ];
1170
1201
}
1171
1202
1172
1203
/**
@@ -1177,10 +1208,18 @@ protected function compileWhereMonth(array $where)
1177
1208
{
1178
1209
extract ($ where );
1179
1210
1180
- $ where ['operator ' ] = $ operator ;
1181
- $ where ['value ' ] = $ value ;
1211
+ $ operator = $ operator === '= ' ? '$eq ' : $ this ->conversion [$ operator ];
1182
1212
1183
- return $ this ->compileWhereBasic ($ where );
1213
+ return [
1214
+ '$expr ' => [
1215
+ $ operator => [
1216
+ [
1217
+ '$month ' => '$ ' .$ column
1218
+ ],
1219
+ $ value ,
1220
+ ],
1221
+ ],
1222
+ ];
1184
1223
}
1185
1224
1186
1225
/**
@@ -1191,10 +1230,18 @@ protected function compileWhereDay(array $where)
1191
1230
{
1192
1231
extract ($ where );
1193
1232
1194
- $ where ['operator ' ] = $ operator ;
1195
- $ where ['value ' ] = $ value ;
1233
+ $ operator = $ operator === '= ' ? '$eq ' : $ this ->conversion [$ operator ];
1196
1234
1197
- return $ this ->compileWhereBasic ($ where );
1235
+ return [
1236
+ '$expr ' => [
1237
+ $ operator => [
1238
+ [
1239
+ '$dayOfMonth ' => '$ ' .$ column
1240
+ ],
1241
+ $ value ,
1242
+ ],
1243
+ ],
1244
+ ];
1198
1245
}
1199
1246
1200
1247
/**
@@ -1204,11 +1251,19 @@ protected function compileWhereDay(array $where)
1204
1251
protected function compileWhereYear (array $ where )
1205
1252
{
1206
1253
extract ($ where );
1254
+
1255
+ $ operator = $ operator === '= ' ? '$eq ' : $ this ->conversion [$ operator ];
1207
1256
1208
- $ where ['operator ' ] = $ operator ;
1209
- $ where ['value ' ] = $ value ;
1210
-
1211
- return $ this ->compileWhereBasic ($ where );
1257
+ return [
1258
+ '$expr ' => [
1259
+ $ operator => [
1260
+ [
1261
+ '$year ' => '$ ' .$ column
1262
+ ],
1263
+ $ value
1264
+ ],
1265
+ ],
1266
+ ];
1212
1267
}
1213
1268
1214
1269
/**
@@ -1219,10 +1274,40 @@ protected function compileWhereTime(array $where)
1219
1274
{
1220
1275
extract ($ where );
1221
1276
1222
- $ where ['operator ' ] = $ operator ;
1223
- $ where ['value ' ] = $ value ;
1277
+ $ operator = $ operator === '= ' ? '$eq ' : $ this ->conversion [$ operator ];
1224
1278
1225
- return $ this ->compileWhereBasic ($ where );
1279
+ $ time = Carbon::parse ($ value );
1280
+
1281
+ return [
1282
+ '$expr ' => [
1283
+ '$and ' => [
1284
+ [
1285
+ $ operator => [
1286
+ [
1287
+ '$hour ' => '$ ' .$ column
1288
+ ],
1289
+ $ time ->hour
1290
+ ],
1291
+ ],
1292
+ [
1293
+ $ operator => [
1294
+ [
1295
+ '$minute ' => '$ ' .$ column
1296
+ ],
1297
+ $ time ->minute
1298
+ ],
1299
+ ],
1300
+ [
1301
+ $ operator => [
1302
+ [
1303
+ '$second ' => '$ ' .$ column
1304
+ ],
1305
+ $ time ->second
1306
+ ],
1307
+ ],
1308
+ ],
1309
+ ],
1310
+ ];
1226
1311
}
1227
1312
1228
1313
/**
0 commit comments