@@ -24,6 +24,8 @@ class SearchParameter extends AbstractParameter
24
24
const LARAVEL_WHERE = 'where ' ;
25
25
const LARAVEL_OR_WHERE = 'orWhere ' ;
26
26
27
+ const RELATION_SEPARATOR = '. ' ;
28
+
27
29
protected OperatorsConfig $ operatorsConfig ;
28
30
29
31
public static function getParameterName (): string
@@ -89,6 +91,17 @@ protected function makeQuery(Builder $builder, array $arguments, string $boolOpe
89
91
continue ;
90
92
}
91
93
94
+ if ($ this ->isRelationSearch ($ key )) {
95
+ // relation search
96
+ [$ rel , $ attr ] = explode (self ::RELATION_SEPARATOR , $ key , 2 );
97
+
98
+ $ builder ->whereHas (Str::camel ($ rel ), function ($ query ) use ($ attr , $ value , $ functionName ) {
99
+ $ this ->makeSingleQuery ($ functionName , $ query , $ attr , $ value );
100
+ });
101
+
102
+ continue ;
103
+ }
104
+
92
105
$ this ->makeSingleQuery ($ functionName , $ builder , $ key , $ value );
93
106
}
94
107
}
@@ -132,6 +145,11 @@ protected function hasSubSearch($key, $value): bool
132
145
return is_string ($ key ) && is_array ($ value );
133
146
}
134
147
148
+ protected function isRelationSearch ($ key ): bool
149
+ {
150
+ return str_contains ($ key , self ::RELATION_SEPARATOR );
151
+ }
152
+
135
153
/**
136
154
* @param string $functionName
137
155
* @param Builder $builder
0 commit comments