tshevchenko / rbac
Role Based Access Control
dev-main
2024-05-15 19:26 UTC
Requires
- php: ^8.1
- tshevchenko/installer: dev-main
This package is not auto-updated.
Last update: 2025-04-30 23:12:58 UTC
README
Role Based Access Control
Installation
composer require tshevchenko/rbac
Migration
Running migrations to create tables in the database
php artisan migrate
ENV constants required:
RBAC_SUPER_ADMIN_EMAIL
- The super admin email used by Seeds to assign the Super Admin role.RBAC_USER_MODEL
- The fully qualified class name of the User model (App\Models\User
)
Config
Publish config file
php artisan vendor:publish --tag=rbac-config
Brief description of settings:
storage
- May bedb
orconfig
. In the case ofdb
the permission will be stored in the database. In the case ofconfig
, the permissions will be taken from thepermissions
property of that configuration file. It might be convenient for small projects with a small number of protected sections.super_admin_email
- see ENVRBAC_SUPER_ADMIN_EMAIL
user_model
- see ENVRBAC_USER_MODEL
super_admin_role_id
- The Role ID Super Admin. This role is granted access without additional checks.permissions
- The array of permissions. Each array element must containrole_id
andaction
'permissions' => [ [ 'role_id' => 4, 'action' => 'App\Http\Controllers\ProfileController@edit', ], ],
excluded_actions
- An array of routes that will be excluded when updatingrbac_actions
table.'excluded_actions' => [ 'generated::', 'ignition.', 'sanctum.', ],
Trait
Use Tshevchenko\Rbac\Models\Traits\RbacTrait
in your User model.
Commands
Use command rbac:actions-update
to update table rbac_actions
. This will update the table according to the existing routes. Always use this command after adding new routes to your application.
Seeds
The sedding data creates 4 access roles to demonstrate capabilities.
- Super Admin, has access to all protected sections, rights to specific actions are not checked.
- Admin, Manager, User - created as an example, the User role is assigned to all existing users.
php artisan db:seed --class=Tshevchenko\\Rbac\\Database\\seeders\\RoleSeeder