laravel-orion
laravel-orion copied to clipboard
Relation resources authorization using parent key
Hello,
While using Orion I spotted a point that could be enhanced.
I have several entities that are related to the Company
model like
companies/{company}/messages
or companies/{company}/documents
.
I have for each to override store method just to change this :
$this->authorize('create', [$resourceModelClass, $parentEntity]);
That makes a lot of code duplication.
I think that in relation controller, passing the parentKey in authorization would be nice, wouldn't it ? if you want I can probably make a pull request for this change if it makes sense to you as well.
EDIT: when you override store
method the response status become a 200 instead of a 201
Hi @DavidSprauel,
I think it would make sense to introduce wrapper methods for authorization, similar to how it is implemented for operations (e.g. performStore
, performUpdate
, etc.) - https://tailflow.github.io/laravel-orion-docs/v2.x/guide/relationships.html#customizing-queries.
Passing parent entity directly to a policy is an app-specific feature and would result in unexpected behavior for many users.
Maybe it is better to create something like createChild
policy method?