Skip to content

Commit c3525f2

Browse files
committed
fix: policy mapping for parent
1 parent 1d469c4 commit c3525f2

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/Http/Api/Contracts/HasParser.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,11 @@ protected function filterByParent(): array
7979
$this->authorize('view', $routeRelation);
8080
}
8181

82-
if ($this->request->isMethod('get') || $this->request->isMethod('options')) {
83-
return [
84-
'filter' => [
85-
$child->{$key}()->getForeignKeyName() => $routeRelation->getKey()
86-
]
87-
];
88-
}
82+
$filter = match (class_basename(get_class($child->{$key}()))) {
83+
'HasOne' => $child->{$key}()->getLocalKeyName(),
84+
'BelongsToMany' => $key . '.' . $child->{$key}()->getRelatedKeyName(),
85+
default => $child->{$key}()->getForeignKeyName(),
86+
};
8987

9088
if ($this->request->isMethod('post') || $this->request->isMethod('put') || $this->request->isMethod('patch')) {
9189
return [

0 commit comments

Comments
 (0)