diff --git a/src/RequestParameters/SearchParameter.php b/src/RequestParameters/SearchParameter.php index 4fe710d..f12f0c4 100644 --- a/src/RequestParameters/SearchParameter.php +++ b/src/RequestParameters/SearchParameter.php @@ -24,6 +24,8 @@ class SearchParameter extends AbstractParameter const LARAVEL_WHERE = 'where'; const LARAVEL_OR_WHERE = 'orWhere'; + const RELATION_SEPARATOR = '.'; + protected OperatorsConfig $operatorsConfig; public static function getParameterName(): string @@ -89,6 +91,17 @@ protected function makeQuery(Builder $builder, array $arguments, string $boolOpe continue; } + if ($this->isRelationSearch($key)) { + // relation search + [$rel, $attr] = explode(self::RELATION_SEPARATOR, $key, 2); + + $builder->whereHas(Str::camel($rel), function ($query) use ($attr, $value, $functionName) { + $this->makeSingleQuery($functionName, $query, $attr, $value); + }); + + continue; + } + $this->makeSingleQuery($functionName, $builder, $key, $value); } } @@ -132,6 +145,11 @@ protected function hasSubSearch($key, $value): bool return is_string($key) && is_array($value); } + protected function isRelationSearch($key): bool + { + return str_contains($key, self::RELATION_SEPARATOR); + } + /** * @param string $functionName * @param Builder $builder