简体   繁体   English

背包的 PermissionManager Laravel -> 我想保护只能编辑权限的用户的路由

[英]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我在: /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我也尝试将该代码放在 Backpack (/routes/backpack/custom.php) 的路径中,但没有结果

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.创建一个routes/backpack/permissionmanager.php文件。 Then Backpack will load YOUR file, instead of the one in the package.然后 Backpack 将加载您的文件,而不是 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. vendor 中的文件将不再使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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