pollob666/acl
Composer 安装命令:
composer require pollob666/acl
包简介
Dynamically configurable access control management for laravel applications
README 文档
README
Dynamically configurable access control for Laravel applications..
install
composer require Pollob666/acl
configure
In your laravel config/app.php under providers add
Pollob666\Acl\AclServiceProvider::class
publish
php artisan vendor:publish
This command will publish view files inside views/vendor/acl,
seed files inside the databases/seed and a config file config/acl.php.
seed
At your DatabaseSeeder.php under database/seeds add the following lines
$this->call(UserTableSeeder::class); //optional $this->call(RoleTableSeeder::class); $this->call(ResourceTableSeeder::class); $this->call(PermissionTableSeeder::class); $this->call(UserRoleTableSeeder::class);
NOTE: If you see any kind of class not found type error try running composer dump-autoload
artisan
This library comes with an artisan command acl:resource to automatically create all the resources (controller@action) available in your project under app/Http/Controllers directory. To activate this command you need to add these following lines to your app/Console/Kernel.php file.
protected $commands = [ \Pollob666\Acl\Commands\AclResource::class ];
@annotation
Acl library now has two annotation support @resource, and @allowRole to be used with controller action
/** * @resource('able to see home') * @allowRole('Default, Admin') */ public function index() { return view('home'); }
NOTE: by default developer role has the highest permission level, and it doesn't need to be mentioned in the
@allowRole annotation. If you remove the @allowRole annotation it won't delete the permissions from the
database, but if you change the role list in the annotation then it will update the databased accordingly.
middleware
This ACL library comes with two middleware as shown below. AuthenticateWithAcl is the middleware you need. The other ResourceMaker middle ware is just a helper to create resource dynamically if it doesn't exists in the first place and assign permission for it to the developer role.
In your kernal.php file add this lines
'auth.acl' => \Pollob666\Acl\Middleware\AuthenticateWithAcl::class, 'resource.maker' => \Pollob666\Acl\Middleware\ResourceMaker::class,
In your route/web.php file add this lines
Route::group(['middleware' => ['resource.maker','auth.acl']], function () { Route::get('/home', 'HomeController@index'); });
IMPORTANT: resource.maker must have to be placed before auth.acl. In production you can remove resource.maker once you have all the resource generated.
Role & Resource UI
To access role visit YOUR-HOST/role url
To access resource UI visit YOUR-HOST/resource url
helpers
has_access checks for if a role has access to a specific controller action.
@if(has_access('User\UserController@getIndex')) OR @if(has_access('UserController@getIndex'))
has_group_access checks for if a role has access to a specific controller
@if(has_group_access(['User-User','User-Role','User-Resource'])) OR @if(has_group_access('User-User'))
@nullsafe() checks for whether any of the object property is null or not in a fluent interface ($obj->prop->value), if the chain is broken it will simply return an empty string and prevent showing up call to a member function of a non-object exception.
Blade example:
{{ @nullsafe($obj->prop->value) }}
Credit(Acknowledgement):
Thanks to Mahbubul Hasan Uzzal for his "https://github.com/mahabubulhasan/acl" package. This package is just an improvement of his codebase for laravel 6 applications and some additional features.
pollob666/acl 适用场景与选型建议
pollob666/acl 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 29 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 05 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「acl」 「laravel」 「dynamic role and permission」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pollob666/acl 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pollob666/acl 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pollob666/acl 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Laravel Multiauth package
Flexslider slideshow content block for Silverstripe Elemental
EAV modeling package for Eloquent and Laravel.
Write down your routing mapping at one place
This package provides a flexible way to add Role-based Permissions to Laravel 6.x
This package provides a flexible way to add Role-based Permissions to Laravel
统计信息
- 总下载量: 29
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-05-23