@@ -236,12 +236,52 @@ protected function parseFiltersArray(array $filters = []): Collection
236
236
$ key => [ 'equals ' => $ value ]
237
237
]
238
238
);
239
+
240
+
239
241
}
240
242
241
243
protected function buildQuery (string $ column , string $ comparison , mixed $ value , mixed $ builder = null ): void
242
244
{
243
245
$ builder ??= $ this ->getBuilder ();
244
246
247
+ $ model = $ builder ->getModel ();
248
+
249
+ if (str ($ column )->contains (". " ) === true ){
250
+ [$ relation , $ key ] = str ($ column )->explode (". " );
251
+ if ($ model ->isRelation ($ relation )) {
252
+
253
+
254
+ $ value = match ($ comparison ) {
255
+ 'is ' ,'equals ' ,'= ' => [
256
+ $ key => $ value
257
+ ],
258
+ '!equals ' ,'not_equals ' ,'!is ' ,'not_is ' ,'! ' ,'!= ' ,'<> ' => [
259
+ $ key => $ value
260
+
261
+ ],
262
+ default => [
263
+ $ key => [
264
+ $ comparison => $ value
265
+ ]
266
+ ]
267
+ };
268
+
269
+ $ comparison = match ($ comparison ){
270
+ 'is ' ,'equals ' ,'= ' => 'has ' ,
271
+ '!equals ' ,'not_equals ' ,'!is ' ,'not_is ' ,'! ' ,'!= ' ,'<> ' => 'not_has ' ,
272
+ default => $ comparison
273
+ };
274
+
275
+ $ column = $ relation ;
276
+ }
277
+ }
278
+
279
+ if ($ model ->isRelation ($ column )) {
280
+ if ($ comparison !== 'has ' && $ comparison !== 'not_has ' ) {
281
+ $ comparison = is_array ($ value ) || filter_var ($ value , FILTER_VALIDATE_BOOL ) === true ? 'has ' : 'not_has ' ;
282
+ }
283
+ }
284
+
245
285
match ($ comparison ){
246
286
'ends_with ' , '$ ' => $ builder ->where ($ column , 'like ' , "% {$ value }" ),
247
287
'!ends_with ' ,'not_ends_with ' , '!$ ' => $ builder ->where ($ column , 'not like ' , "% {$ value }" ),
@@ -274,6 +314,7 @@ protected function buildQuery(string $column, string $comparison, mixed $value,
274
314
protected function filtersHasClause (string $ relation , string $ method , mixed $ value , mixed $ builder ): void
275
315
{
276
316
317
+
277
318
$ rel = Helpers::camel ($ relation );
278
319
$ relatedModel = $ builder ->getModel ()->$ rel ()->getModel ();
279
320
$ callback = is_array ($ value );
@@ -287,6 +328,7 @@ protected function filtersHasClause(string $relation, string $method, mixed $val
287
328
)
288
329
: null
289
330
);
331
+
290
332
}
291
333
292
334
0 commit comments