Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How implement 'remember me' in laravel 5.1?

How to implement rememeber me functionality in laravel 5.1? Can anyone give me an example?

like image 930
Neethu Avatar asked Jan 07 '16 09:01

Neethu


People also ask

How do you implement remember me in laravel?

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.

How do you implement remember me in laravel 8?

Your users table must include the string remember_token column, which will be used to store the "remember me" token. if (Auth::attempt(['email' => $email, 'password' => $password], $remember)) { // The user is being remembered... }


1 Answers

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

like image 117
jedrzej.kurylo Avatar answered Sep 19 '22 23:09

jedrzej.kurylo