PHP-Casbin 是一个用 PHP 语言打造的轻量级开源访问控制框架。PHP-Casbin 采用了元模型的设计思想,支持多种经典的访问控制方案,如基于角色的访问控制 RBAC、基于属性的访问控制 ABAC 等。
Laraval-Casbin 是一个专为Laravel定制的Casbin的扩展包。
Casbin
composer require casbin/laravel-adapter
php artisan vendor:publish
php artisan migrate
use \Casbin; $sub = "alice"; // the user that wants to access a resource. $obj = "data1"; // the resource that is going to be accessed. $act = "read"; // the operation that the user performs on the resource. if (Casbin::enforce($sub, $obj, $act) === true) { // permit alice to read data1 } else { // deny the request, show an error }
Casbin 官方网站:https://casbin.org
Laraval-Casbin 的更多用法: https://github.com/php-casbin/laravel-casbin
有问题请提交 Issues: https://github.com/php-casbin/laravel-casbin/issues