I am trying to implement the remember me functionality in my web site using Auth::viaRemember() but it always returns a value of false. what causes this and how to resolve this issue?
The remeber_token generates and stores it in database fine.
Here's the things i've tried:
- Change the the value of
'expire_on_close'from false to true inconfig/session.php - Cleared the cookies and google chrome browser cache then restarted my browser
- ran the
php artisan config:cacheandphp artisan route:clear - Logged in with remember me checked then logged out (to see if the crendentials was saved).
Here's my login method code inside LoginController.php:
public function login(Request $request)
{
$this->validate($request, [
'email' => 'required|email',
'password' => 'required',
]);
$remember = $request->has('remember') ? true : false;
if (Auth::attempt(['email' => $request->input('email'), 'password' => $request->input('password')], $remember))
{
if(Auth::viaRemember())
{
dd("remembered successfully");
}else{
dd("failed to remember");
}
return view('home');
}else{
return back()->with('error','your username and password are wrong.');
}
}
Here's my snippet code of login.blade.php file:
<div class="form-group row">
<div class="col-md-6 offset-md-4">
<div class="form-check">
<input class="form-check-input" type="checkbox" name="remember" id="remember" {{ old('remember') ? 'checked' : '' }}>
<label class="form-check-label" for="remember">
{{ __('Remember Me') }}
</label>
</div>
</div>
</div>
Here's the login page just in case:
There's no problem in logging in and successfully redirects to the home page. The only problem is that the credentials are not showing up or the log in form does not remember the credentials logged in before with remember me checked.
Had the same problem with this post and its references/posts included:
Auth::viaRemember() doesnot work (means always return false even after successful login) in laravel 5.4 but unfortunately none of the provided solution works for me..
P.S.
I am using Laravel Framework 7.14.1 and latest google chrome version as of this moment (Version 83.0.4103.97 (Official Build) (64-bit))
