Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php laravel5,\Auth::check(),返回true,但trunt()返回false_Php_Laravel - Fatal编程技术网

Php laravel5,\Auth::check(),返回true,但trunt()返回false

Php laravel5,\Auth::check(),返回true,但trunt()返回false,php,laravel,Php,Laravel,登录后,我想在控制器之前添加逻辑,所以我在中间件中编写了。 但是,我发现当我 dd(\Auth::check()); // it returns true; 但是 整个代码: public function handle($request, Closure $next) { dd(\Auth::check()); $eid = \Auth::user()->eid; $password = \Auth::user()->password; dd(\

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

dd(\Auth::check());  // it returns true;
但是

整个代码:

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()

是eid和password两列我想在登录后添加逻辑,但我只能获取哈希密码,如何获取明文密码?您只能在用户输入时获取。现在您可以通过哈希本身获取密码
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);
}