Download the PHP package huang-yi/laravel-rbac without Composer
On this page you can find all versions of the php package huang-yi/laravel-rbac. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download huang-yi/laravel-rbac
More information about huang-yi/laravel-rbac
Files in huang-yi/laravel-rbac
Informations about the package laravel-rbac
English | 中文
Laravel RBAC
This package helps you to manage permissions and roles.
Installation
You may install this package via Composer:
Next, you should publish configuration and migration files using the vendor:publish Artisan command:
Finally, you should run your database migrations:
Configuration
- user: The user model class you are using.
- database:
- connection: The database connection for RBAC tables.
- prefix: The common prefix for RBAC tables.
- cache: The cache switch.
Usage
Your User model must be configured to rbac.user option. It should implement the HuangYi\Rbac\Contracts\Authorizable interface and use the HuangYi\Rbac\Concerns\Authorizable trait.
Store a permission to database:
Store a role to database:
Attach or detach permissions to role:
Attach or detach roles to user:
Attach or detach permissions to user:
Determine if the user has roles:
Determine if the user has permissions:
Super Admin
You may register a callback for determining if the user is a super admin by using Rbac::checkSuperAdminUsing() method:
Middleware
Blade Directives
Role directives:
@role,@elserole,@endrole→hasRole@roles,@elseroles,@endroles→hasRoles@anyroles,@elseanyroles,@endanyroles→hasAnyRoles
Permission directives:
@permission,@elsepermission,@endpermission→hasPermission@permissions,@elsepermissions,@endpermissions→hasPermissions@anypermissions,@elseanypermissions,@endanypermissions→hasAnyPermissions
Tests
License
This package is open-sourced software licensed under the MIT license.