@@ -236,12 +236,52 @@ protected function parseFiltersArray(array $filters = []): Collection
236236 $ key => [ 'equals ' => $ value ]
237237 ]
238238 );
239+
240+
239241 }
240242
241243 protected function buildQuery (string $ column , string $ comparison , mixed $ value , mixed $ builder = null ): void
242244 {
243245 $ builder ??= $ this ->getBuilder ();
244246
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+
245285 match ($ comparison ){
246286 'ends_with ' , '$ ' => $ builder ->where ($ column , 'like ' , "% {$ value }" ),
247287 '!ends_with ' ,'not_ends_with ' , '!$ ' => $ builder ->where ($ column , 'not like ' , "% {$ value }" ),
@@ -274,6 +314,7 @@ protected function buildQuery(string $column, string $comparison, mixed $value,
274314 protected function filtersHasClause (string $ relation , string $ method , mixed $ value , mixed $ builder ): void
275315 {
276316
317+
277318 $ rel = Helpers::camel ($ relation );
278319 $ relatedModel = $ builder ->getModel ()->$ rel ()->getModel ();
279320 $ callback = is_array ($ value );
@@ -287,6 +328,7 @@ protected function filtersHasClause(string $relation, string $method, mixed $val
287328 )
288329 : null
289330 );
331+
290332 }
291333
292334
0 commit comments