parseAuthorizationArguments makes it impossible to specify custom policy

I want to specify a custom policy to check against in my ->authorize() in a relation manager.
CreateAction::make('upload')
->authorize('createMedia', $this->getOwnerRecord())
// ...
CreateAction::make('upload')
->authorize('createMedia', $this->getOwnerRecord())
// ...
In the trait CanBeAuthorized the following code is present:
protected function parseAuthorizationArguments(array $arguments): array
{
if ($record = $this->getRecord()) {
array_unshift($arguments, $record);
} elseif ($model = $this->getModel()) {
array_unshift($arguments, $model);
}

return $arguments;
}
protected function parseAuthorizationArguments(array $arguments): array
{
if ($record = $this->getRecord()) {
array_unshift($arguments, $record);
} elseif ($model = $this->getModel()) {
array_unshift($arguments, $model);
}

return $arguments;
}
This code always prepends the current model class to the arguments array. This causes the passed $this->getOwnerRecord() to be treated as an argument instead of the class to check the policy against. How can I authorize against a policy I choose?
Solution:
We ended up solving this by creating another model which extends media and using that in the relationship.
Jump to solution
1 Reply
Solution
Proculair B.V.
Proculair B.V.4mo ago
We ended up solving this by creating another model which extends media and using that in the relationship.

Did you find this page helpful?