lewis15520/lararoles
Composer 安装命令:
composer require lewis15520/lararoles
包简介
A roles and permissions system for laravel
README 文档
README
A package to add roles and permissions to laravel
Requirements
- PHP 7.3 or later
- Laravel 8 or later
Installation
In order to run Lararoles you are required to follow these steps in your terminal
- Install the package with
composer require lewis15520/lararoles - Copy the required package conents with
php artisan vendor:publish --provider="Lewis15520\Lararoles\app\Providers\LararolesServiceProvider" - Install the package migrations with
php artisan migrate
Usage
Adding the trait
In your User model, add the following lines in the use cases: use Lewis15520\Lararoles\Traits;. Then, inside the class, above the functions, add the following: use Lararoles;
Checking the roles and permissions
Anywhere around the application where you have a user object (including from the auth()->user() helper), you can add attach a series of functions to check roles and permissions.
-
hasRole: Usage "
$user->hasRole('roleName');" | Definition "This will check for a singular role attached to this user." -
hasRoles: Usage "
$user->hasRoles(['role1Name', 'role2Name'], (optional) $requireAll = false);" | Definition "This will check if atleast one of the roles given is attached to the user, unless the$requireAllvariable is set totrue, then it will only pass if all the roles are attached to the user." -
hasPermission: Usage "
$user->hasPermission('permissionName');" | Definition "This will check for a singular permission attached to this user through their attached roles." -
hasPermissions: Usage "
$user->hasPermissions(['permission1Name', 'permission2Name'], (optional) $requireAll = false);" | Definition "This will check if atleast one of the permissions given is attached to one of the roles that the user is assigned to, unless the$requireAllvariable is set totrue, then it will only pass if all the permissions are associated."
lewis15520/lararoles 适用场景与选型建议
lewis15520/lararoles 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 961 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 11 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 lewis15520/lararoles 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lewis15520/lararoles 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 961
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: mit
- 更新时间: 2020-11-15