问题
Before I posted this, I did some searching but still I don't know it always return false. My code is below
html
<input type="checkbox" name="remember"/> {{ trans('login.text_remember_me') }}
controller
$remember = ($request->has('remember')) ? true : false;
if (Auth::attempt($credentials, $remember))
Then after successful logged-in. I checked the dd(Auth::viaRemember()); and it return false. Even changed my config/session.php setting 'expire_on_close' => true from false.
Basically what I want is when the user tick the remember me checkbox I will set the session lifetime to 3 days else to 1 day only.
Updated
From $request->all() here are the result after clicking the login button with checked remember me
array:6 [▼
"_token" => "...."
"email" => "myemail@gmail.com"
"password" => "...."
"remember" => "on"
"uri" => ""
"code" => ""
]
then I removed in my dashboard controller I checked the viaRemember method
dd(Auth::viaRemember()); // result: false
回答1:
Update your this line
$remember = ($request->has('remember')) ? true : false;
to this, and then check.
$remember = ($request->get('remember') == 'on') ? true : false;
回答2:
add "id = remember me" to input field
<input type="checkbox" name="remember" id="remember"/>
not sure.
来源:https://stackoverflow.com/questions/39885982/via-remember-me-always-return-false