[英]Laravel - Auth::check() returning false, but middleware auth not redirecting
So somehow i was managed to produce a situation where Auth::check() says that i'm not logged in, but middleware('auth') is still allowing acces to my class. 因此,我设法以某种方式产生了一种情况,其中Auth :: check()表示我尚未登录,但中间件('auth')仍允许访问我的课程。 The last thing i did was modify user data, but I did not log out, so im assuming Auth::check() is returning the wrong value.
我做的最后一件事是修改用户数据,但是我没有注销,因此我假设Auth :: check()返回错误的值。 But why could it be so?
但是为什么会这样呢? My controller construct:
我的控制器构造:
public function __construct()
{
if(Auth::check()){
print "yes";
} else {
print "no";
};
$this->middleware('auth');
}
public function index()
{
print " index";
}
This prints out "no index". 这将打印出“无索引”。 So Auth::check() return false, but index method is still raeched.
因此Auth :: check()返回false,但是索引方法仍然被搜索。
The constructor is called before the middleware. 在中间件之前调用构造函数。 Laravel allows you to provide controller middleware, so you push to the middleware stack from within a controllers constructor.
Laravel允许您提供控制器中间件,因此您可以从控制器构造函数中推送到中间件堆栈。
Any form of session interaction in the constructor of a controller will fail. 控制器的构造函数中的任何形式的会话交互都将失败。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.