sudippalash/role-creator

Laravel 角色管理包

1.2.0 2024-03-29 20:47 UTC

This package is auto-updated.

Last update: 2024-09-29 21:50:25 UTC


README

alt text

Latest Version on Packagist Total Downloads

role-creator 是一个 Laravel 角色管理包,提供用于管理认证用户角色的选项。

注意:此包是 spatie/laravel-permission 包的封装。

安装

通过 Composer

composer require sudippalash/role-creator

发布配置、迁移和种子文件

您应该发布

迁移文件

  1. database/migrations/create_permission_tables.php
  2. database/migrations/add_module_column_to_permissions_table.php,

配置文件

  1. config/permission.php,
  2. config/role-creator.php

以及种子文件

  1. database/seeders/PermissionSeeder.php

使用以下命令

php artisan vendor:publish --provider="Sudip\RoleCreator\Providers\AppServiceProvider" --tag=required

对于 config/permission.php 文件,您应该查看 spatie/laravel-permission 包的文档。

这是已发布配置文件 config/role-creator.php 的内容

    return [
        /*
        |--------------------------------------------------------------------------
        | Extends Layout Name
        |--------------------------------------------------------------------------
        |
        | Your main layout file path name. Example: layouts.app
        | 
        */

        'layout_name' => 'layouts.app',
        
        /*
        |--------------------------------------------------------------------------
        | Section Name
        |--------------------------------------------------------------------------
        |
        | Your section name which in yield in main layout file. Example: content
        | 
        */

        'section_name' => 'content',

        /*
        |--------------------------------------------------------------------------
        | Route Name, Prefix & Middleware
        |--------------------------------------------------------------------------
        |
        | Provide a route name for role route. Example: user.roles
        | Provide a prefix name for role url. Example: user/roles
        | If role route use any middleware then provide it or leave empty array. Example: ['auth'] 
        */

        'route_name' => 'user.roles',
        'route_prefix' => 'user/roles',
        'middleware' => [],
        
        /*
        |--------------------------------------------------------------------------
        | Role & Permission Name Pretty Print 
        |--------------------------------------------------------------------------
        |
        | You can set the delimiter to separate your role/permission name for pretty preview
        | Example: array('-', '_', '=', '|', '/')
        | 
        */

        'role_permission_name_separator' => ['-', '_'],

        /*
        |--------------------------------------------------------------------------
        | Auth Guard Name
        |--------------------------------------------------------------------------
        |
        | Which authentication guard you use for role. Example: web or admin
        | 
        */

        'auth_guard_name' => 'web',

        /*
        |--------------------------------------------------------------------------
        | Role Prevent
        |--------------------------------------------------------------------------
        |
        | Those role names hide from list and prevent from edit & delete. Example ['Super Admin']
        |
        */

        'hide_role_names' => [],

        /*
        |--------------------------------------------------------------------------
        | Bootstrap version
        |--------------------------------------------------------------------------
        |
        | Which bootstrap you use in your application. Example: 3 or 4 or 5
        | 
        */

        'bootstrap_v' => 4,

        /*
        |--------------------------------------------------------------------------
        | Flash Messages
        |--------------------------------------------------------------------------
        |
        | After Save/Update flash message session key name
        | 
        */

        'flash_success' => 'success',
        'flash_error' => 'error',

        /*
        |--------------------------------------------------------------------------
        | CSS
        |--------------------------------------------------------------------------
        |
        | Add your css class in this property if you want to change design. 
        */

        'css' => [
            'container' => null,
            'card' => null,
            'input' => null,
            'btn' => null,
            'table' => null,
            'table_action_col_width' => null,
            'table_action_btn' => null,
        ],
    ];

可选地,您可以使用以下命令发布视图

php artisan vendor:publish --provider="Sudip\RoleCreator\Providers\AppServiceProvider" --tag=views

可选地,您可以使用以下命令发布语言包

php artisan vendor:publish --provider="Sudip\RoleCreator\Providers\AppServiceProvider" --tag=lang

您应该使用以下命令运行迁移

php artisan migrate

database/seeders/PermissionSeeder.php 种子文件中,您应该设置您的权限数据,然后使用以下命令运行种子

php artisan db:seed --class=PermissionSeeder

使用方法

您应该复制以下行并将其粘贴到您的项目菜单部分

<a href="{{ route(config('role-creator.route_name') . '.index') }}">{{ trans('role-creator::sp_role_creator.roles') }}</a>

如果您想为多个守卫使用此包,则可以使用 RoleCreator 特性。(可选)

use Sudip\RoleCreator\Traits\RoleCrud;

class YourController extends Controller
{
    use RoleCrud;
    
    protected $guardName, $routeName;

    public function __construct()
    {
        $this->guardName = '{your new guard_name}';
        $this->routeName = '{your resource route name}';
    }
}