Skip to content

Commit ada618a

Browse files
committed
feat:Update README.md
1 parent 416b9d6 commit ada618a

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

README.md

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ Before configuring the database and publishing the role-permission files, add th
3030
HasPermissionsTrait
3131
```
3232

33-
3433
```php
3534
<?php
3635

@@ -130,6 +129,21 @@ if (hasPermissions('post-create')) {
130129
dd('You are not allowed to access');
131130
}
132131
```
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+
```
133147

134148
To get all permissions:
135149

@@ -172,7 +186,7 @@ Route::group(['middleware' => ['role:admin,post-create']], function () {
172186

173187
You can also use Blade directives to display content based on the user's role:
174188

175-
```php
189+
```blade
176190
@role('admin')
177191
{{ __('You are an admin') }}
178192
@endrole
@@ -186,10 +200,21 @@ You can also use Blade directives to display content based on the user's role:
186200

187201
You can also use Blade directives to display content based on the user's permissions:
188202

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')
191216
{{ __('You can create a post') }}
192-
@endpermission
217+
@endhasPermissions
193218
```
194219

195220
## Example Seeder for Roles and Permissions
@@ -238,7 +263,7 @@ class RolePermissionSeeder extends Seeder
238263
{
239264
$roles = [
240265
'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'],
242267
];
243268

244269
foreach ($roles as $roleName => $permissionNames) {
@@ -260,15 +285,14 @@ class RolePermissionSeeder extends Seeder
260285
'email' => 'admin@gmail.com',
261286
'password' => Hash::make('admin'),
262287
'roles' => ['admin'],
263-
'permissions' => ['post-create'],
288+
'permissions' => ['post-create', 'post-edit'],
264289
],
265290
[
266291
'name' => 'User',
267292
'email' => 'user@gmail.com',
268293
'password' => Hash::make('user'),
269294
'roles' => ['user'],
270-
'permissions' => ['user-create'],
271-
'permissions' => ['user-create'],
295+
'permissions' => ['user-create', 'user-edit'],
272296
],
273297
];
274298

0 commit comments

Comments
 (0)