How to implement rememeber me functionality in laravel 5.1? Can anyone give me an example?
Asked
Active
Viewed 2.6k times
6
-
Have you try to find or to do something, what kind of application are you trying to do? – Sylvain Martin Jan 07 '16 at 09:45
2 Answers
16
Laravel authentication offers remember me functionality out of the box.
In order to use it you need to do 2 things:
- add remember_token column in your users table - this is where the token will be stored
- pass true as a second parameter of Auth::attempt() to enable remember me behaviour
If you do this, Laravel will generate a token that will be saved in users table and in a cookie. On subsequent requests, even if session cookie is not available, user will be authenticated automatically as long as remember-me cookie is there.
You can find more details and example in the docs: https://laravel.com/docs/5.1/authentication#remembering-users

jedrzej.kurylo
- 39,591
- 9
- 98
- 107
-
Nice, this is also available in Laravel 4.2 as I look into my project using old version. – Jovylle Mar 29 '21 at 17:44
2
laravel can provide a remember me functionality.
you can use simply.
public function login(Request $req)
{
$req->validate([
'username' => 'required|email|min:8|max:50',
'password' => 'required|min:8|max:50'
]);
$remember_me = $req->has('remember_me') ? true : false;
$check = $req->only('username', 'password');
if(Auth::attempt($check, $remember_me))
{
return redirect('admin/dashboard');
}
else
{
session()->put('error-msg', "Please enter the valid username and password");
return redirect('admin/login');
}
}

Viral Ghodadara
- 70
- 1
- 6