winex01/backpack-permission-manager

在 Laravel Backpack 权限管理器插件创建中查看清单的组角色和权限字段

1.2.3 2024-08-11 14:51 UTC

This package is auto-updated.

Last update: 2024-09-11 14:58:44 UTC


README

Latest Version on Packagist Total Downloads The Whole Fruit Manifesto

此包覆盖了 Backpack PermissionManager 并将清单字段的角色和权限显示为组。请查看 Laravel 权限管理器包的设置方法。

屏幕截图

Backpack Permission Manager Extension

安装

通过 Composer

composer require winex01/backpack-permission-manager

别忘了将守卫设置为 null

//config/backpack/base.php

// The guard that protects the Backpack admin panel.
// If null, the config.auth.defaults.guard value will be used.
// 'guard' => 'backpack',
'guard' => null

种子

php artisan vendor:publish --provider="Winex01\BackpackPermissionManager\BackpackPermissionManagerServiceProvider" --tag="seeders"

运行种子

php artisan db:seed --class=RolesAndPermissionsSeeder

用法

它是如何工作的,我使用的是 role_permission 规约

'admin' => [
  'admin_view',
  'admin_trashed_filter', 
  'admin_debugbar', 
  'admin_web_tinker', 
  'admin_notify_newly_registered',
  'admin_notify_newly_created_manga',
  'admin_proxy_notice',
  'admin_telescope',
  'admin_widgets',
  'admin_received_contact_us',
  'admin_reply_contact_us',
]

'audit_trails' => [
  'audit_trails_list',
  'audit_trails_show', 
  'audit_trails_delete',
  'audit_trails_bulk_delete',
  'audit_trails_export',
  'audit_trails_restore_revise',
  'audit_trails_bulk_restore_revise', 
]

限制没有权限的用户

//EntityCrudController.php
use Winex01\BackpackPermissionManager\Http\Controllers\Traits\UserPermissions;

public function setup()
{
    // some code here...
    
    // Option 1:
    $this->userPermissions('user'); // it will check all permission that starts with user_ (i recommend to use prefix such as: user_list, user_create and etc..)

    // Option 2:
    $this->userPermissions(); // if you follow roleName_permissionName and use the table's name as your roleName then you can leave it empty.

    // Option 3:
    // calling $this->userPermissions method is equivalent:
    $this->crud->denyAllAccess(); // if you want to use the checkAccess method dont forget to call denyAllAccess method first
    $this->checkAccess('users');
    $this->checkAccess('admin');
}

卸载此包。

composer remove winex01/backpack-permission-manager

变更日志

变更记录在此处记录在 Github 上。请参阅 发布标签

测试

composer test

贡献

请参阅 contributing.md 了解待办事项和操作指南。

安全性

如果您发现任何与安全性相关的问题,请通过电子邮件 winnie131212592@gmail.com 而不是使用问题跟踪器。

致谢

许可协议

该项目基于 MIT 协议发布,因此您可以在任何 Backpack & Laravel 项目上安装它。有关更多信息,请参阅 许可文件

但是,请注意,您需要安装 Backpack,因此您也需要遵守其 YUMMY 许可协议。这意味着在生产环境中,您需要 Backpack 许可代码。您可以在 backpackforlaravel.com 上获得免费的非商业用途许可(或商业用途的付费许可)。