diff --git a/README.md b/README.md index 4c7511a..6209e7f 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ To assign a role to a user: ```php $user = User::find(1); // Replace with the appropriate user ID -$user->assignRoleByName('Admin'); +$user->assignRole('Admin'); ``` #### Get User's Role @@ -69,8 +69,31 @@ To check if a user has a specific permission: if ($user->hasPermission('edit-user')) { // The user has permission to edit a user } + +IN blade.php + +@hasPermission('edit-user') + {{ show the content if user has this permission }} +@endhasPermission ``` +### Functions List +`role`: Return the Role collection of modal. + +`hasRole` `@hasRole` : Check Loggedin User has the role. + +`hasAnyRole` `@hasAnyRole` : Checks if the user has any of the specified roles. + +`permission`: Get the permission collection from permission modal. + +`@hasPermission` `@haspermission`: Check Loggedin user has the permission. + +`hasAnyPermission` `@hasAnyPermission`: Checks if the user has any of the specified permissions. + +`hasAllPermission` `@hasAllPermission`: Verifies that the user has all the specified permissions. + +`hasExactPermissions` `@hasExactPermissions`: Checks if the user has exactly the specified permissions. + ## Seeding Roles and Permissions You can create a seeder to start with some default roles and permissions. For example: @@ -97,7 +120,7 @@ class RolesAndPermissionsSeeder extends Seeder // Create a user and assign the role $user = User::create(['name' => 'Admin User', 'email' => 'admin@example.com', 'password' => bcrypt('password')]); - $user->assignRoleByName('Admin'); + $user->assignRole('Admin'); } } ``` @@ -112,5 +135,3 @@ Ensure your database schema is set up correctly. The following tables should exi ## Conclusion 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. - - diff --git a/src/PermissionsServiceProvider.php b/src/PermissionsServiceProvider.php index a9b4d75..280bf78 100644 --- a/src/PermissionsServiceProvider.php +++ b/src/PermissionsServiceProvider.php @@ -32,16 +32,14 @@ public function boot(): void }; // Role checks - $bladeCompiler->if('role', fn() => $bladeMethodWrapper('hasRole', ...func_get_args())); - $bladeCompiler->if('hasrole', fn() => $bladeMethodWrapper('hasRole', ...func_get_args())); - $bladeCompiler->if('hasanyrole', fn() => $bladeMethodWrapper('hasAnyRole', ...func_get_args())); + $bladeCompiler->if('hasRole', fn() => $bladeMethodWrapper('hasRole', ...func_get_args())); + $bladeCompiler->if('hasAnyRole', fn() => $bladeMethodWrapper('hasAnyRole', ...func_get_args())); // Permission checks - $bladeCompiler->if('permission', fn() => $bladeMethodWrapper('hasPermission', ...func_get_args())); - $bladeCompiler->if('haspermission', fn() => $bladeMethodWrapper('hasPermission', ...func_get_args())); - $bladeCompiler->if('hasanypermission', fn() => $bladeMethodWrapper('hasAnyPermission', ...func_get_args())); - $bladeCompiler->if('hasallpermissions', fn() => $bladeMethodWrapper('hasAllPermissions', ...func_get_args())); - $bladeCompiler->if('hasexactpermissions', fn() => $bladeMethodWrapper('hasExactPermissions', ...func_get_args())); + $bladeCompiler->if('hasPermission', fn() => $bladeMethodWrapper('hasPermission', ...func_get_args())); + $bladeCompiler->if('hasAnyPermission', fn() => $bladeMethodWrapper('hasAnyPermission', ...func_get_args())); + $bladeCompiler->if('hasAllPermissions', fn() => $bladeMethodWrapper('hasAllPermissions', ...func_get_args())); + $bladeCompiler->if('hasExactPermissions', fn() => $bladeMethodWrapper('hasExactPermissions', ...func_get_args())); // Ending directive for permissions $bladeCompiler->directive('endunlesspermission', fn() => ''); @@ -60,3 +58,4 @@ public function register(): void $this->mergeConfigFrom(__DIR__ . '/config/permissions.php', 'permissions'); // Ensure this matches the config file } } +