How to implement rememeber me functionality in laravel 5.1? Can anyone give me an example?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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