Coder Social home page Coder Social logo

laravel-rbac's Introduction

laravel-rbac

基于laravel的后台权限管理拓展包,精确到接口的权限管理

  1. 使用 composer 安装

    composer require sczts/laravel-rbac
  2. 发布配置文件

    # 这条命令会在 config 下增加一个 rbac.php 的配置文件
    php artisan vendor:publish --provider="Sczts\Rbac\Providers\RbacServiceProvider"
  3. 修改配置文件 config/rbac.php 填写实际的用户表名/模型,配置对应使用的auth中间件

            'user' => 'users',
            'middleware' => [
                'api',
                // 'jwt.auth',
                // 'auth.api',
                // 'auth:sanctum',
            ],
    
  4. 进行数据库迁移

    php artisan migrate
  5. 填充默认角色与权限信息(可选)

    php artisan db:seed --class=RbacPermissionSeeder
    php artisan db:seed --class=RbacRoleSeeder
  6. 给User模型添加 trait UserPermission

    use Sczts\Rbac\Traits\UserPermission;
    
    class User extends Authenticatable
    {
        use Notifiable, UserPermission;
    //......
  7. 在路由中添加验证中间件 rbac.check:{keyword}

    // 示例代码:
    Route::group(['prefix' => 'role', 'middleware' => ['api', 'auth:sanctum']], function () {
        Route::get('/', 'RoleController@list')->middleware('rbac.check:sys_role.list');
        Route::post('/', 'RoleController@store')->middleware('rbac.check:sys_role.add');
        Route::get('/{id}', 'RoleController@show')->middleware('rbac.check:sys_role.show');
        Route::put('/{id}', 'RoleController@update')->middleware('rbac.check:sys_role.update');
        Route::delete('/{id}', 'RoleController@destroy')->middleware('rbac.check:sys_role.delete');
    });

laravel-rbac's People

Contributors

eiixy avatar

Watchers

 avatar

Forkers

eiixy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.