登录后,我想在控制器之前添加逻辑,所以我在中间件中写道。 但是,我发现我
dd(\Auth::check()); // it returns true;
但是
$eid = \Auth::user()->eid; //can print the value
$password = \Auth::user()->password; //can print the value, too
dd(\Auth::validate(['eid'=>$eid,'password'=>$password])); //it returns false
整个代码:
public function handle($request, Closure $next)
{
dd(\Auth::check());
$eid = \Auth::user()->eid;
$password = \Auth::user()->password;
dd(\Auth::validate(['eid'=>$eid,'password'=>$password]));
if ($this->auth->guest())
{ // not login
if ($request->ajax())
{
return response('Unauthorized.', 401);
}
else
{
return redirect()->guest('auth/login');
}
}
return $next($request);
}
答案 0 :(得分:0)
Auth::user()->password
是密码哈希,不能在validate()
函数中使用。您只能在Auth::validate()