How To Add Remember Me Functionality to Laravel Login?
we always use remember me option in login page, that way user don't require to login everytime. So, we would like use remember me option in our login page then you can also do it simply, because laravel provide it's own functionality. But, many developer can't do it properly i mean remember me not working, but you can implement it right.
First you have to sure that remember_token field in our users table. if you haven't remember_token column then first add it in your users table or any table that you use as for auth.
Now you should have controller method this way:
Example:
public function webLoginPost(Request $request)
{
$this->validate($request, [
'email' => 'required|email',
'password' => 'required',
]);
$remember_me = $request->has('remember_me') ? true : false;
if (auth()->attempt(['email' => $request->input('email'), 'password' => $request->input('password')], $remember_me))
{
$user = auth()->user();
dd($user);
}else{
return back()->with('error','your username and password are wrong.');
}
}
try this...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel 10 Custom Login and Registration Example
- Laravel 10 REST API with Passport Authentication Tutorial
- Laravel 10 Authentication using Jetstream Tutorial
- Laravel Login with Mobile Number OTP Tutorial
- Laravel Login and Registration using Ajax Tutorial
- Laravel Passwordless Login with Magic Link Tutorial
- Laravel Google 2FA Authentication Tutorial Example
- Laravel 9 Multi Auth: Create Multiple Authentication in Laravel
- How to Override Auth Register Method in Laravel 8?
- How to Add Two Factor Authentication with SMS in Laravel?
- How to Set Limit Login Attempts in Laravel?
- Laravel Login with Linkedin using Socialite Package
- How to Make Custom Middleware in Laravel?