PHP code example of sczts / laravel-rbac

1. Go to this page and download the library: Download sczts/laravel-rbac library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sczts / laravel-rbac example snippets


    use Sczts\Rbac\Traits\UserPermission;
    
    class User extends Authenticatable
    {
        use Notifiable, UserPermission;
    //......
    

    // 示例代码:
    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');
    });
    
bash
    # 这条命令会在 config 下增加一个 rbac.php 的配置文件
    php artisan vendor:publish --provider="Sczts\Rbac\Providers\RbacServiceProvider"
    
bash
    php artisan migrate
    
bash
    php artisan db:seed --class=RbacPermissionSeeder
    php artisan db:seed --class=RbacRoleSeeder