简体   繁体   中英

PermissionManager for Backpack Laravel -> I want to protect the Routes to Users that only can Edit Permissions

I made this in: /vendor/backpack/permissionmanager/src/routes/backpack/permissionmanager.php

Route::group([
    'namespace'  => 'Backpack\PermissionManager\app\Http\Controllers',
    'prefix'     => config('backpack.base.route_prefix', 'admin'),
    'middleware' => ['web', backpack_middleware()],
], function () {
    Route::group(['middleware' => ['can:edit permissions']], function () { <---- I added this code
        Route::crud('permission', 'PermissionCrudController');
        Route::crud('role', 'RoleCrudController');
        Route::crud('user', 'UserCrudController');
    }); <---- I added this code
});

It doesn't work

But I know is not a good idea to do it like this, touching the vendor folder

How can I handle this situation?

Also I've tried to put that code inside the routes of Backpack (/routes/backpack/custom.php), with no results

Indeed, changing things in the vendor directory is a big no-no. But you can easily do the same in your app. You can see in this package's docs, under overwriting functionality that there's an easier solution for that:

Create a routes/backpack/permissionmanager.php file. Then Backpack will load YOUR file, instead of the one in the package.

Remember to include ALL routes from the vendor file and all your overwrites too. The file in the vendor will no longer be used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM