💡Roles & Permissions
We are using Spatie Laravel Permission composer package to manage role and permission
Config Roles and Default Permission
You can find "config\enums.php" for default roles and permission. you can add roles as show in below array
System can have default roles as many as you want. you can also add roles runtime in system after setup.
Default Permission
Each role must have default permission key to decide it's default permission when executing seeder script. if * is provided like Super Admin then it will assign all permission to that role. Or else you can specify list of permission that will be going to assigned to specific role like User in above example.
Custom Permission
When you execute seeder script you will get all permission based on route names but sometime you may need some custom permission that can't be related to any route or it's names. in this case you can give this permission names list as array in custom_permission for specific role and seeder script will create permission (if not exists) with this name and assign it to the specific role in which custom_permission is added. You can use that permission name in your code to manage permission access. as show in below example
Update Roles & Permissions
After updating your route file you need to run Optimize Clear Command
We have already written script in seeder "database\seeders\RolesAndPermissionsSeeder.php".
So You just need to run seeder to get Default Roles & permission as per "config/enums.php" and routes names as permission. Once execution is completed then you can user permission it in your code.
Permission to ignore
If you don't want to add some of your routes in permission as you want to make it open then you can add those route names in "config/enums.php" : permission_to_ignore array so script will ignore those route names while creating permission.
Last updated