From the docs我可以看到将参数editor
传递给您编写的中间件role
Route::put('post/{id}', ['middleware' => 'role:editor', function ($id) {
...
}]);
要在中间件中使用该参数,只需将参数传递给句柄函数
即可public function handle($request, Closure $next, $role)
{
...
}
我的问题是,这个editor
参数来自哪里?我只能看到传递的URL字符串中的id
。
答案 0 :(得分:4)
handle参数中的$role
变量将包含role:
之后传入的变量
因此role:editor
将返回"editor"
答案 1 :(得分:2)
您必须设置角色参数。 editor
可以是admin
,user
,moderator
等,然后将此值传递给handle方法。有关更多详细信息,请参阅以下链接:https://mattstauffer.co/blog/passing-parameters-to-middleware-in-laravel-5.1