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 +94,11 @@ The `Authorizable` trait on the `User` entity provides the following methods to
87
94
88
95
#### can()
89
96
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
97
+
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
98
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.
99
+
permissions (**group-level permissions**) to determine if they are allowed. When checking against group-level permissions, this includes evaluating
100
+
hierarchical wildcard permissions. For example, if a user's group has the permission `forum.posts.*`, a check for `$user->can('forum.posts.create')`
101
+
would return `true`.
93
102
94
103
```php
95
104
if ($user->can('users.create')) {
@@ -100,8 +109,26 @@ if ($user->can('users.create')) {
100
109
if ($user->can('users.create', 'users.edit')) {
101
110
//
102
111
}
112
+
113
+
// Example with hierarchical wildcard check.
114
+
// Assuming the $user is in a group with 'forum.posts.*' permission.
115
+
if ($user->can('forum.posts.create')) {
116
+
// This will return true
117
+
}
103
118
```
104
119
120
+
When checking group-level permissions, Shield automatically creates a hierarchy check by examining parent permissions:
121
+
122
+
- For permission `forum.posts.create`, it checks: `forum.posts.create`, `forum.posts.*`, and `forum.*`
123
+
- For permission `admin.settings`, it checks: `admin.settings` and `admin.*`
124
+
125
+
This allows for flexible permission management where broader permissions automatically grant access to more specific actions.
126
+
127
+
!!! warning
128
+
129
+
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.
130
+
131
+
105
132
#### inGroup()
106
133
107
134
Checks if the user is in one of the groups passed in. Returns boolean `true`/`false`.
0 commit comments