@@ -30,7 +30,6 @@ Before configuring the database and publishing the role-permission files, add th
30
30
HasPermissionsTrait
31
31
```
32
32
33
-
34
33
``` php
35
34
<?php
36
35
@@ -130,6 +129,21 @@ if (hasPermissions('post-create')) {
130
129
dd('You are not allowed to access');
131
130
}
132
131
```
132
+ OR
133
+
134
+ ``` php
135
+ if (hasPermissions('post-create|post-edit')) {
136
+ dd('You are allowed to access');
137
+ } else {
138
+ dd('You are not allowed to access');
139
+ }
140
+
141
+ if (hasPermissions('post-create,post-edit')) {
142
+ dd('You are allowed to access');
143
+ } else {
144
+ dd('You are not allowed to access');
145
+ }
146
+ ```
133
147
134
148
To get all permissions:
135
149
@@ -172,7 +186,7 @@ Route::group(['middleware' => ['role:admin,post-create']], function () {
172
186
173
187
You can also use Blade directives to display content based on the user's role:
174
188
175
- ``` php
189
+ ``` blade
176
190
@role('admin')
177
191
{{ __('You are an admin') }}
178
192
@endrole
@@ -186,10 +200,21 @@ You can also use Blade directives to display content based on the user's role:
186
200
187
201
You can also use Blade directives to display content based on the user's permissions:
188
202
189
- ``` php
190
- @permission('post-create')
203
+ ``` blade
204
+ @hasPermissions('post-create')
205
+ {{ __('You can create a post') }}
206
+ @endhasPermissions
207
+ ```
208
+ OR
209
+
210
+ ``` blade
211
+ @hasPermissions('post-create|post-edit')
212
+ {{ __('You can create a post') }}
213
+ @endhasPermissions
214
+
215
+ @hasPermissions('post-create,post-edit')
191
216
{{ __('You can create a post') }}
192
- @endpermission
217
+ @endhasPermissions
193
218
```
194
219
195
220
## Example Seeder for Roles and Permissions
@@ -238,7 +263,7 @@ class RolePermissionSeeder extends Seeder
238
263
{
239
264
$roles = [
240
265
'admin' => ['post-create', 'post-edit', 'post-delete', 'post-update'],
241
- 'user' => ['user-create, 'user-edit', 'user-delete', 'user-update'],
266
+ 'user' => ['user-create' , 'user-edit', 'user-delete', 'user-update'],
242
267
];
243
268
244
269
foreach ($roles as $roleName => $permissionNames) {
@@ -260,15 +285,14 @@ class RolePermissionSeeder extends Seeder
260
285
'email' => 'admin@gmail.com',
261
286
'password' => Hash::make('admin'),
262
287
'roles' => ['admin'],
263
- 'permissions' => ['post-create'],
288
+ 'permissions' => ['post-create', 'post-edit' ],
264
289
],
265
290
[
266
291
'name' => 'User',
267
292
'email' => 'user@gmail.com',
268
293
'password' => Hash::make('user'),
269
294
'roles' => ['user'],
270
- 'permissions' => ['user-create'],
271
- 'permissions' => ['user-create'],
295
+ 'permissions' => ['user-create', 'user-edit'],
272
296
],
273
297
];
274
298
0 commit comments