Skip to content

Commit 557d275

Browse files
committed
fix AggregateFilterable
1 parent 94725d8 commit 557d275

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/Rules/AggregateFilterable.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,19 @@ public function resource($resource)
6363
*/
6464
protected function buildValidationRules($attribute, $value)
6565
{
66-
if (is_null($this->resource)) {
67-
return [];
66+
$rules = [];
67+
68+
foreach ($this->data['search']['aggregates'] as $aggregate) {
69+
$resource = $this->resource->relation($aggregate['relation'])?->resource();
70+
71+
if (is_null($this->resource)) {
72+
continue;
73+
}
74+
75+
array_push($rules, (new SearchRules($resource, app()->make(RestRequest::class), false))->filtersRules($resource, $attribute));
6876
}
6977

70-
return (new SearchRules($this->resource, app()->make(RestRequest::class), false))
71-
->filtersRules(
72-
$this->resource,
73-
$attribute
74-
);
78+
return $rules;
7579
}
7680

7781
/**

src/Rules/IsNestedField.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,9 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
4343
$fail('The '.$attribute.' field is not valid.');
4444
}
4545
}
46+
47+
public function __toString()
48+
{
49+
return 'nested_field';
50+
}
4651
}

0 commit comments

Comments
 (0)