shitoudev/permissionmanager
Composer 安装命令:
composer require shitoudev/permissionmanager
包简介
Users and permissions management interface for Laravel 5 using Backpack CRUD.
关键字:
README 文档
README
An admin interface to easily add/edit/remove users, roles and permissions, using Laravel Backpack. As opposed to some other packages:
- a user can have multiple roles;
- a user can have extra permissions, in addition to the permissions on the roles he has;
Security updates and breaking changes
Please subscribe to the Backpack Newsletter so you can find out about any security updates, breaking changes or major features. We send an email every 1-2 months.
Install
- In your terminal:
$ composer require backpack/permissionmanager
- Add the service provider to your config/app.php file:
Backpack\PermissionManager\PermissionManagerServiceProvider::class,
- Publish the config file & run the migrations
$ php artisan vendor:publish --provider="Backpack\PermissionManager\PermissionManagerServiceProvider" #publish config files and migrations $ php artisan migrate #create the role and permission tables
- Use the following traits on your User model:
<?php namespace App; use Backpack\CRUD\CrudTrait; // <------------------------------- this one use Spatie\Permission\Traits\HasRoles;// <---------------------- and this one use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { use CrudTrait; // <----- this use HasRoles; // <------ and this /** * Your User Model content */
- [Optional] Add a menu item for it in resources/views/vendor/backpack/base/inc/sidebar.blade.php or menu.blade.php:
<!-- Users, Roles Permissions --> <li class="treeview"> <a href="#"><i class="fa fa-group"></i> <span>Users, Roles, Permissions</span> <i class="fa fa-angle-left pull-right"></i></a> <ul class="treeview-menu"> <li><a href="{{ url(config('backpack.base.route_prefix', 'admin') . '/user') }}"><i class="fa fa-user"></i> <span>Users</span></a></li> <li><a href="{{ url(config('backpack.base.route_prefix', 'admin') . '/role') }}"><i class="fa fa-group"></i> <span>Roles</span></a></li> <li><a href="{{ url(config('backpack.base.route_prefix', 'admin') . '/permission') }}"><i class="fa fa-key"></i> <span>Permissions</span></a></li> </ul> </li>
- [Optional] Disallow create/update on your roles or permissions after you define them, using the config file in config/backpack/permissionmanager.php. Please note permissions and roles are referenced in code using their name. If you let your admins edit these strings and they do, your permission and role checks will stop working.
API Usage
Because the package requires spatie/laravel-permission, the API will be the same:
Using permissions
A permission can be given to a user:
$user->givePermissionTo('edit articles');
A permission can be revoked from a user:
$user->revokePermissionTo('edit articles');
You can test if a user has a permission:
$user->hasPermissionTo('edit articles');
Saved permissions will be registered with the Illuminate\Auth\Access\Gate-class. So you can test if a user has a permission with Laravel's default can-function.
$user->can('edit articles');
Using roles and permissions
A role can be assigned to a user:
$user->assignRole('writer');
A role can be removed from a user:
$user->removeRole('writer');
You can determine if a user has a certain role:
$user->hasRole('writer');
You can also determine if a user has any of a given list of roles:
$user->hasAnyRole(Role::all());
You can also determine if a user has all of a given list of roles:
$user->hasAllRoles(Role::all());
The assignRole, hasRole, hasAnyRole, hasAllRoles and removeRole-functions can accept a string, a Role-object or an \Illuminate\Support\Collection-object.
A permission can be given to a role:
$role->givePermissionTo('edit articles');
You can determine if a role has a certain permission:
$role->hasPermissionTo('edit articles');
A permission can be revoked from a role:
$role->revokePermissionTo('edit articles');
The givePermissionTo and revokePermissionTo-functions can accept a string or a Permission-object.
Saved permission and roles are also registered with the Illuminate\Auth\Access\Gate-class.
$user->can('edit articles');
Using blade directives
This package also adds Blade directives to verify whether the currently logged in user has all or any of a given list of roles.
@role('writer') I\'m a writer! @else I\'m not a writer... @endrole @hasrole('writer') I\'m a writer! @else I\'m not a writer... @endhasrole @hasanyrole(Role::all()) I have one or more of these roles! @else I have none of these roles... @endhasanyrole @hasallroles(Role::all()) I have all of these roles! @else I don\'t have all of these roles @endhasallroles
You can use Laravels native @can directive to check if a user has a certain permission.
Change log
Please see CHANGELOG for more information what has changed recently.
Screenshots
Testing
// TODO
Overwriting functionality
If you need to modify how this works in a project:
- create a
routes/backpack/permissionmanager.phpfile; the package will see that, and load your routes file, instead of the one in the package; - create controllers/models that extend the ones in the package, and use those in your new routes file;
- modify anything you'd like in the new controllers/models;
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email hello@tabacitu.ro instead of using the issue tracker.
Please subscribe to the Backpack Newsletter so you can find out about any security updates, breaking changes or major features. We send an email every 1-2 months.
Credits
- Marius Constantin - Lead Developer
- Cristian Tabacitu - Chief Architect
- All Contributors
License
Backpack is free for non-commercial use and $19/project for commercial use. Please see License File and backpackforlaravel.com for more information.
shitoudev/permissionmanager 适用场景与选型建议
shitoudev/permissionmanager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 08 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「manage users」 「dick」 「tabacitu」 「updivision」 「backpack」 「laravel backpack」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 shitoudev/permissionmanager 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 shitoudev/permissionmanager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 shitoudev/permissionmanager 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Debugging a problem and need to login as one of your customers? This allows you to authenticate as any of your customers.
Forked from https://github.com/deltaaskii/lara-pdf-merger. Add condition if(!class_exists('TCPDF')) (depreciated in php 7.2) to foreach.
A trait for Laravel models which have many users with roles.
The library provides a flexible way to add role-based access control management to CakePHP 3.x
Authorization package for ARCANESOFT/Foundation.
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-08-05