leafwrap / role-sanctions
Role sanction is a succinct and flexible way to add Role-based Permissions to Laravel
0.0.3
2023-11-04 07:43 UTC
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; } }