Att*_*lop 3 php authorization laravel laravel-5.3
我正在尝试通过文档中描述的中间件保护路由
当我点击网址时,我得到:
ReflectionException in Container.php line 749:
Class can does not exist
Run Code Online (Sandbox Code Playgroud)
这是来自routes.php:的相关部分:
Route::get('{user}/profile/edit/{type?}', [
'as' => 'edit',
'uses' => 'User\UserController@edit',
'middleware' => ['can:edit-user,user'],
]);
Run Code Online (Sandbox Code Playgroud)
AuthServiceProvider.php:
public function boot()
{
$this->registerPolicies();
// ... other definitions
Gate::define('edit-user', function ($user, $subjectUser) {
return
$user->hasRole('manage.user') // if the user has this role, green
||
($user->isAdmin && $user->id == $subjectUser->id) // otherwise if is admin, can edit her own profile
;
});
Run Code Online (Sandbox Code Playgroud)
也许是因为我没有使用单独的策略类来定义门?
根据使用带有路由的中间件的文档- 您需要在app/Http/Kernel.php
如果您希望在对应用程序的每个 HTTP 请求期间运行中间件,只需在 app/Http/Kernel.php 类的 $middleware 属性中列出中间件类。
您看到的错误表明缺少此定义。你需要添加类似的东西;
// Within App\Http\Kernel Class...
protected $routeMiddleware = [
//...
'can' => \Path\To\Your\Middleware::class,
];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3447 次 |
| 最近记录: |