You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -87,9 +92,11 @@ The `Authorizable` trait on the `User` entity provides the following methods to
87
92
88
93
#### can()
89
94
90
-
Allows you to check if a user is permitted to do a specific action or group or actions. The permission string(s) should be passed as the argument(s). Returns
95
+
Allows you to check if a user is permitted to do a specific action or group of actions. The permission string(s) should be passed as the argument(s). Returns
91
96
boolean `true`/`false`. Will check the user's direct permissions (**user-level permissions**) first, and then check against all of the user's groups
92
-
permissions (**group-level permissions**) to determine if they are allowed.
97
+
permissions (**group-level permissions**) to determine if they are allowed. When checking against group-level permissions, this includes evaluating
98
+
hierarchical wildcard permissions. For example, if a user's group has the permission `forum.posts.*`, a check for `$user->can('forum.posts.create')`
99
+
would return `true`.
93
100
94
101
```php
95
102
if ($user->can('users.create')) {
@@ -100,8 +107,25 @@ if ($user->can('users.create')) {
100
107
if ($user->can('users.create', 'users.edit')) {
101
108
//
102
109
}
110
+
111
+
// Example with hierarchical wildcard check.
112
+
// Assuming the $user is in a group with 'forum.posts.*' permission.
113
+
if ($user->can('forum.posts.create')) {
114
+
// This will return true
115
+
}
103
116
```
104
117
118
+
When checking group-level permissions, Shield automatically creates a hierarchy check by examining parent permissions:
119
+
120
+
- For permission `forum.posts.create`, it checks: `forum.posts.create`, `forum.posts.*`, and `forum.*`
121
+
- For permission `admin.settings`, it checks: `admin.settings` and `admin.*`
122
+
123
+
This allows for flexible permission management where broader permissions automatically grant access to more specific actions.
124
+
125
+
!!! warning
126
+
127
+
Be cautious when granting wildcard permissions, especially at high levels like `admin.*`, as they will grant access to any future permissions added under that scope.
128
+
105
129
#### inGroup()
106
130
107
131
Checks if the user is in one of the groups passed in. Returns boolean `true`/`false`.
0 commit comments