Skip to content

Commit a62b318

Browse files
committed
changes regrading adding new functionality
1 parent 9c9a7dd commit a62b318

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

README.md

+25-4
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ To assign a role to a user:
5454

5555
```php
5656
$user = User::find(1); // Replace with the appropriate user ID
57-
$user->assignRoleByName('Admin');
57+
$user->assignRole('Admin');
5858
```
5959

6060
#### Get User's Role
@@ -69,8 +69,31 @@ To check if a user has a specific permission:
6969
if ($user->hasPermission('edit-user')) {
7070
// The user has permission to edit a user
7171
}
72+
73+
IN blade.php
74+
75+
@hasPermission('edit-user')
76+
{{ show the content if user has this permission }}
77+
@endhasPermission
7278
```
7379

80+
### Functions List
81+
`role`: Return the Role collection of modal.
82+
83+
`hasRole` `@hasRole` : Check Loggedin User has the role.
84+
85+
`hasAnyRole` `@hasAnyRole` : Checks if the user has any of the specified roles.
86+
87+
`permission`: Get the permission collection from permission modal.
88+
89+
`@hasPermission` `@haspermission`: Check Loggedin user has the permission.
90+
91+
`hasAnyPermission` `@hasAnyPermission`: Checks if the user has any of the specified permissions.
92+
93+
`hasAllPermission` `@hasAllPermission`: Verifies that the user has all the specified permissions.
94+
95+
`hasExactPermissions` `@hasExactPermissions`: Checks if the user has exactly the specified permissions.
96+
7497
## Seeding Roles and Permissions
7598
You can create a seeder to start with some default roles and permissions. For example:
7699

@@ -97,7 +120,7 @@ class RolesAndPermissionsSeeder extends Seeder
97120

98121
// Create a user and assign the role
99122
$user = User::create(['name' => 'Admin User', 'email' => '[email protected]', 'password' => bcrypt('password')]);
100-
$user->assignRoleByName('Admin');
123+
$user->assignRole('Admin');
101124
}
102125
}
103126
```
@@ -112,5 +135,3 @@ Ensure your database schema is set up correctly. The following tables should exi
112135

113136
## Conclusion
114137
This package provides a simple way to manage user roles and permissions in your Laravel application. For further customization or additional features, feel free to contribute or reach out for support.
115-
116-

src/PermissionsServiceProvider.php

+7-8
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,14 @@ public function boot(): void
3232
};
3333

3434
// Role checks
35-
$bladeCompiler->if('role', fn() => $bladeMethodWrapper('hasRole', ...func_get_args()));
36-
$bladeCompiler->if('hasrole', fn() => $bladeMethodWrapper('hasRole', ...func_get_args()));
37-
$bladeCompiler->if('hasanyrole', fn() => $bladeMethodWrapper('hasAnyRole', ...func_get_args()));
35+
$bladeCompiler->if('hasRole', fn() => $bladeMethodWrapper('hasRole', ...func_get_args()));
36+
$bladeCompiler->if('hasAnyRole', fn() => $bladeMethodWrapper('hasAnyRole', ...func_get_args()));
3837

3938
// Permission checks
40-
$bladeCompiler->if('permission', fn() => $bladeMethodWrapper('hasPermission', ...func_get_args()));
41-
$bladeCompiler->if('haspermission', fn() => $bladeMethodWrapper('hasPermission', ...func_get_args()));
42-
$bladeCompiler->if('hasanypermission', fn() => $bladeMethodWrapper('hasAnyPermission', ...func_get_args()));
43-
$bladeCompiler->if('hasallpermissions', fn() => $bladeMethodWrapper('hasAllPermissions', ...func_get_args()));
44-
$bladeCompiler->if('hasexactpermissions', fn() => $bladeMethodWrapper('hasExactPermissions', ...func_get_args()));
39+
$bladeCompiler->if('hasPermission', fn() => $bladeMethodWrapper('hasPermission', ...func_get_args()));
40+
$bladeCompiler->if('hasAnyPermission', fn() => $bladeMethodWrapper('hasAnyPermission', ...func_get_args()));
41+
$bladeCompiler->if('hasAllPermissions', fn() => $bladeMethodWrapper('hasAllPermissions', ...func_get_args()));
42+
$bladeCompiler->if('hasExactPermissions', fn() => $bladeMethodWrapper('hasExactPermissions', ...func_get_args()));
4543

4644
// Ending directive for permissions
4745
$bladeCompiler->directive('endunlesspermission', fn() => '<?php endif; ?>');
@@ -60,3 +58,4 @@ public function register(): void
6058
$this->mergeConfigFrom(__DIR__ . '/config/permissions.php', 'permissions'); // Ensure this matches the config file
6159
}
6260
}
61+

0 commit comments

Comments
 (0)