我的认证中间件有一些问题。我想用它来保护我的路线,但在一些控制器中它真的不起作用。如果我作为注销用户检查路由,我得到了不同的错误消息,而不是阻止访问并重定向到登录页面。我总是在控制器的__construct()之上使用中间件。
一个例子。控制器
public function show(Dialog $dialog)
{
return $this->template($dialog, self::DISPLAY_MODE_DIALOG);
}
protected function template(Dialog $dialog, $displayMode, $messageLimit = 10)
{
$user = Auth::user();
// Check if the profile is currently controlled by the current user
$isControlled = $dialog->moderator()->appProfile()->isControlledBy($user->id);
$messageList = $dialog->latestMessages($messageLimit);
return view('dialog.chat.template')
->with(compact('dialog', 'messageList', 'isControlled', 'displayMode'));
}
模型public function isAccessibleBy(User $user)
{
$profile = $this->moderator()->appProfile();
return $profile->isOwner($user->id)
|| $profile->isControlledBy($user->id);
}
误差参数1传递给App'Model'Dialog'Dialog::isAccessibleBy()必须是App'Model'Account'User的一个实例,null给定,在C:'projekte'php'newchat' App'Model'Dialog'Dialog .php中调用并定义
现在我知道为什么会发生这种情况,但我认为中间件不应该显示此消息并保护路由。
http://laravel.com/docs/5.0/middleware"然而,如果用户经过身份验证,中间件将允许请求进一步进入应用程序。"
我用ryanmortier的解决方案解决了我的问题。从LPMadness的方式对我不起作用。
https://github.com/laravel/framework/issues/6118