Allow hasAllPermissions
and hasAnyPermission
to run on custom guard for wildcard permissions
#2596
Closed
AlexandreBellas
started this conversation in
Ideas
Replies: 1 comment 6 replies
-
Thanks for the detailed writeup. I think your point about checking the guard only if it is not a model is probably the simplest and most logical fix. Within if ($permission instanceof Permission) {
$permission = $permission->name;
+ $guard_name = $permission->guard_name;
} |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm using wildcard permissions. Nowadays, in the trait
HasPermissions.php
, there is the following code:There isn't a way to define a custom guard for
hasAllPermissions
. By the way, in the methodcheckPermissionTo
there is, as inhasPermissionTo
.My initial thought was "well, if
hasAllPermissions
doesn't have a way to define my custom guard, so sending the permission models (as they know their guard) would be enough, right?". In reality, this is not the case. The default guard is chosen inhasWildcardPermission
.It's important to notice that
hasAllPermissions
has a spread-operator argument, which disallows to inform the desired guard as a function argument.It would be nice to make
hasWildcardPermission
run theimplies
logic over the guard of eachPermission
model, and if it is not a model but a string/ID/etc, then it would use the default guard or any logic that would make sense.The same applies to
hasAnyPermission
, in the same conditions (wildcard permissions, spread operator argument blocking new ones, usage ofcheckPermissionTo
andhasPermissionTo
).Surely I could use a
foreach
using onlycheckPermissionTo
with the custom guard or even override thehasAllPermissions
method in the model, but the idea is to improve the developer experience when using the package.What do you think? Does this make sense?
Beta Was this translation helpful? Give feedback.
All reactions