marksihor/laravel-permissions
Composer 安装命令:
composer require marksihor/laravel-permissions
包简介
Laravel permissions.
README 文档
README
Laravel Roles and Permissions package.
Installing
$ composer require marksihor/laravel-permissions -vvv
Migrations
This step is optional, if you want to customize the tables, you can publish the migration files:
$ php artisan vendor:publish --provider="MarksIhor\\LaravelPermissions\\PermissionsServiceProvider" --tag=migrations
Configs
To publish configs run the command:
$ php artisan vendor:publish --provider="MarksIhor\\LaravelPermissions\\PermissionsServiceProvider" --tag=configs
Controllers
This step is optional, if you want to get crud controller (instead of use built in routes) run the command:
$ php artisan vendor:publish --provider="MarksIhor\\LaravelPermissions\\PermissionsServiceProvider" --tag=controllers
If You published the controller, add the routes to your routes file:
Route::group(['as' => 'roles', 'prefix' => 'roles'/*, 'middleware' => 'permission:view roles'*/], function () { Route::get('/', 'RoleController@index'); Route::get('/{model}', 'RoleController@show'); Route::get('/{model}/permissions', 'RoleController@permissions')/*->middleware('permission:view roles')*/; Route::post('/', 'RoleController@store')/*->middleware('permission:create roles')*/; Route::patch('/{model}', 'RoleController@update')/*->middleware('permission:update roles')*/; Route::delete('/{model}', 'RoleController@delete')/*->middleware('permission:delete roles')*/; Route::patch('/{model}/permissions/{action}', 'RoleController@updatePermissions') ->where('action', '(attach|detach|update)') /*->middleware('permission:update roles')*/; });
Usage
1 . Run migrations
php artisan migrate
- Add next line to $routeMiddleware array of your Kernel.php file
'permission' => \MarksIhor\LaravelPermissions\Http\Middleware\PermissionMiddleware::class,
- Add role relationship to your user model
public function role() { return $this->belongsTo('MarksIhor\LaravelPermissions\Models\Role'); }
- Use it on route like this
Route::get('/', 'UserController@index')->middleware('permission:view users');
- Or in other places like this
app('auth')->user()->role->hasPermission($permissionName); // bool
License
MIT
marksihor/laravel-permissions 适用场景与选型建议
marksihor/laravel-permissions 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.32k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 08 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 marksihor/laravel-permissions 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 marksihor/laravel-permissions 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 6.32k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-08-13