laravel5 ,Auth::check(),返回 true,但 try() 返回 false



登录后,我想在控制器之前添加逻辑,所以我在中间件中写了。但是,我发现当我

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);
}

Auth::user()->password是密码哈希,不能validate()函数中使用。您只能在Auth::validate()中使用实际的明文密码

最新更新