Some thoughts on this. I was thinking that maybe the way to go could be to pass an array of permissions needed from the controller to the policy.
The UserController update would look like:
$this->authorize('update', [$user, Role::findByName('Organizer')->permissions]);
The AdminController update would look like:
$this->authorize('update', [$user, Role::findByName('Admin')->permissions]);
And then on the UserPolicy update method, pass this additional parameter and check that all permissions are met:
public function update(User $user, User $model, Collection $permissions)
{
foreach ($permissions as $permission) {
$this->authorize($permission->name);
}
//additional logic
}
Since this is something that would be used platform-wide it would be nice to maybe extend the base policy class to always check if there are permissions and validate them beforehand, but I'm not sure how it could be done. I think that passing this array can do for a decent solution for now though 🤔.