首页 > 解决方案 > 'can' 中间件与 Laravel 中的 Route::resource

问题描述

我想对资源的所有路由应用授权检查。例如:

我可以通过在资源路由上应用“can”中间件来实现这一点,例如:

Route::resource('doctors', 'DoctorsController')->middleware('can:*,App\Doctor');

谢谢!

标签: laravelroutesauthorizationmiddlewareuser-roles

解决方案


在 DoctorsController 构造函数中,您可以使用:

$this->middleware('can:<something>,App\Doctor');

参考:https://stackoverflow.com/questions/28729228/laravel-5-route-resources-middleware


推荐阅读