laravel - 'can' 中间件与 Laravel 中的 Route::resource
问题描述
我想对资源的所有路由应用授权检查。例如:
- 管理员可以创建医生
- 管理员可以更新医生
- 管理员可以查看医生
- 管理员可以删除医生
我可以通过在资源路由上应用“can”中间件来实现这一点,例如:
Route::resource('doctors', 'DoctorsController')->middleware('can:*,App\Doctor');
谢谢!
解决方案
在 DoctorsController 构造函数中,您可以使用:
$this->middleware('can:<something>,App\Doctor');
参考:https://stackoverflow.com/questions/28729228/laravel-5-route-resources-middleware
推荐阅读
- python - 如何将此 lambda 函数转换为 def 格式?
- android - 有人可以澄清这是泄漏吗?
- javascript - JQuery在浏览器刷新时刷新ajax数据
- javascript - 服务器端处理表分页 - 数据表或任何其他?
- r - 在 r shiny 中创建新变量 = 现有变量 + 用户输入
- vb.net - 如何通过vb.net代码解析数据链接webform。
- java - 尝试将 Java 应用程序连接到 Redshift 数据库时服务器关闭连接
- react-native - 如何在从数据库中获取数据数组时保持显示按钮等组件
- perl - perl 主程序永远等待
- java - 如何从 System.out.println() 中删除尾随空格;爪哇