tshevchenko / rbac
Role Based Access Control
Installs: 14
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Forks: 0
Type:tshevchenko-package
pkg:composer/tshevchenko/rbac
Requires
- php: ^8.1
- tshevchenko/installer: dev-main
This package is not auto-updated.
Last update: 2025-12-11 02:17:56 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 bedborconfig. In the case ofdbthe permission will be stored in the database. In the case ofconfig, the permissions will be taken from thepermissionsproperty 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_EMAILuser_model- see ENVRBAC_USER_MODELsuper_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_idandaction'permissions' => [ [ 'role_id' => 4, 'action' => 'App\Http\Controllers\ProfileController@edit', ], ],excluded_actions- An array of routes that will be excluded when updatingrbac_actionstable.'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