Download the PHP package huang-yi/rbac-laravel without Composer
On this page you can find all versions of the php package huang-yi/rbac-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package rbac-laravel
关于Rbac-Laravel
Rbac-Laravel是一个基于Laravel框架的RBAC拓展包,RBAC(Role-Based Access Control)是指基于角色的访问控制。该拓展包为Laravel框架提供了RBAC模型的实现,并且提供了诸多操作RBAC的便捷方法。
版本信息
Rbac | Laravel | PHP |
---|---|---|
1.0.x | 5.3.* | >=5.6.4 |
安装方法
使用composer来快速安装拓展包:
或者编辑项目根目录的composer.json
文件,在require
属性里面添加一项:
然后执行composer update
。
配置信息
首先往Laravel应用中注册ServiceProvider,打开文件config/app.php
,在providers
中添加一项:
然后发布拓展包的配置文件,使用如下命令:
这时候config/
目录下会出现rbac.php
文件,该配置文件中有两个配置选项:
第一个为connection
属性,用于配置RBAC模块使用的数据库连接名。
第二个为user
属性,用于配置Laravel应用中使用的用户模型。默认为App\User
。
上述配置文件中所配置的user模型类必须use HuangYi\Rbac\RbacTrait
:
数据迁移
执行以下命令创建拓展包必须依赖的数据库表:
使用方法
Permission
1、权限有三个属性:name
,slug
,description
。
2、创建一个权限:HuangYi\Rbac\Managers\PermissionManager::create(array $attributes)
3、删除一个权限:HuangYi\Rbac\Managers\PermissionManager::delete($ID)
删除权限时会自动解绑已绑定的角色。
4、更新一个权限:HuangYi\Rbac\Managers\PermissionManager::update($ID, array $attributes)
5、查询一个权限:HuangYi\Rbac\Managers\PermissionManager::find($ID)
Role
1、角色有三个属性:name
,slug
,description
。
2、创建一个角色:HuangYi\Rbac\Managers\RoleManager::create(array $attributes)
3、删除一个角色:HuangYi\Rbac\Managers\RoleManager::delete($ID)
删除角色时会自动解绑已绑定的用户和权限。
4、更新一个角色:HuangYi\Rbac\Managers\RoleManager::update($ID, array $attributes)
5、查询一个角色:HuangYi\Rbac\Managers\RoleManager::find($ID)
6、为角色绑定权限:HuangYi\Rbac\Managers\RoleManager::attachPermissions($permissionIDs)
7、为角色解绑权限:HuangYi\Rbac\Managers\RoleManager::detachPermissions($permissionIDs)
User
1、为用户绑定角色:HuangYi\Rbac\RbacTrait::attachRoles($roleIDs)
2、为用户解绑角色:HuangYi\Rbac\RbacTrait::detachRoles($roleIDs)
3、判断用户是否为某些角色,若需要判断多个角色请使用|
间隔:HuangYi\Rbac\RbacTrait::hasRole($roles)
4、判断用户是否拥有某些权限,若需要判断多个权限请使用|
间隔:HuangYi\Rbac\RbacTrait::hasPermission($permissions)
Middleware
Rbac-Laravel为开发人员提供了便利的Middleware,如果需要使用请将HuangYi\Rbac\RbacMiddleware
注入到app/Http/Kernel.php
中的路由中间件里:
配置好后即可在路由中使用:
在视图中使用
支持
Bugs和问题可提交至Github,或者请联系作者黄毅([email protected])
License
The Rbac-Laravel is open-sourced software licensed under the MIT license