Laravel viaRemember总是返回false [英] Laravel viaRemember always returning false
问题描述
我在保持用户登录方面遇到麻烦,因此进行了一些测试,我注意到viaRemember函数始终返回 false
.
I've had trouble with keeping my users logged in, so I did some testing and I noticed that the function viaRemember always returns false
.
这是我的登录控制器功能,其中删除了所有不相关的代码:
This is my login controller function with all the irrelevant code stripped off:
public function postSignin(Request $request, AppMailer $mailer) {
$this->validate($request, [
'email' => 'required',
'password' => 'required',
]);
$username = $request->get('email');
$password = $request->get('password');
$field = filter_var($username,FILTER_VALIDATE_EMAIL)? 'email': 'username';
Auth::attempt([$field => $username, 'password' => $password], true);
return redirect()->back()->with('info', 'You are now signed in.');
}
工作正常.如您所见,默认情况下, Auth :: attempt
中的第二个参数设置为 true
.
Works fine. As you can see the 2nd argument in Auth::attempt
is set to true
by default.
在我的数据库中,"remember_token"的值在每次登录时都会更改,因此似乎可以正常使用.但是,如果我执行 dd(Auth :: viaRemember());
,结果将始终为 false
.
In my database, the value for "remember_token" is changed at every login, so that appears to be working. However, if I do dd(Auth::viaRemember());
the result will always be false
.
我也尝试更改我的 config/session.php
设置,切换一些值,但这似乎并没有太大作用.
I tried changing my config/session.php
settings as well, switching some values around, but that doesn't seem to do much.
为什么会这样?
推荐答案
我认为您误解了此功能."viaRemember"用于检查返回用户是否通过记住我"功能进行了身份验证.绝对是第一次使用记住我"登录时,此操作将返回false.尝试关闭浏览器,然后再次打开,它将返回true.
I think you misunderstood this feature. "viaRemember" is to check whether the returning user is authenticated via "remember me" function. Definitely the first time you login with "remember me" checked this will return false. Try closing your browser and open up again it will return true.
或者您可以通过进入 config \ session.php 并进行更改
Or you can do its behavior by going in config\session.php and change
'expire_on_close' = false
真实,一切都如您所想
这篇关于Laravel viaRemember总是返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!