leafwrap/role-sanctions
最新稳定版本:0.0.3
Composer 安装命令:
composer require leafwrap/role-sanctions
包简介
Role sanction is a succinct and flexible way to add Role-based Permissions to Laravel
README 文档
README
Role sanction is a succinct and flexible way to add Role-based Permissions to Laravel
Installation
Use the package manager composer to install leafwrap/role-sanctions.
composer require leafwrap/role-sanctions
You can publish the config file with:
php artisan vendor:publish --tag=role-sanctions
Usage
Step 1
Add all your modules in config/role-sanctions.php
'modules' => [ ...modules ],
Step 2
After adding all modules demonstrate all gates in AuthServiceProviders
if(auth()->check() && auth()->user()->role){ RoleSanction::demonstrate(auth()->user()->role); }
Step 3
Then certify your role ability in your controller methods
use Leafwrap\RoleSanctions\Facades\RoleSanction; public function index() { try { # if use api $certify = RoleSanction::certify('{module}-{action}'); # e.g. $certify = RoleSanction::certify('user-read'); if(!$certify){ return response()->json(['message' => 'Unauthorized'], 403); } # if use general purpose RoleSanction::certify('{module}-{action}'); # e.g. $certify = RoleSanction::certify('user-read'); ... your code } catch (Exception $e) { return $e; } }
统计信息
- 总下载量: 555
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-02-10