The "Remember me" feature helps users stay logged in even after closing the browser. It saves time by not asking for login details every visit.
Remember me functionality in Laravel
Auth::attempt(['email' => $email, 'password' => $password], $remember);
The second parameter $remember is a boolean. Set it to true to enable "Remember me".
This method tries to log in the user and sets a long-lasting cookie if $remember is true.
$credentials = ['email' => $email, 'password' => $password]; Auth::attempt($credentials, true);
$credentials = ['email' => $email, 'password' => $password]; Auth::attempt($credentials, false);
This controller method logs in a user using email and password. It checks if the "remember" checkbox is checked and passes that to Auth::attempt. If successful, it confirms login and whether "remember me" is active.
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; class LoginController extends Controller { public function login(Request $request) { $credentials = $request->only('email', 'password'); $remember = $request->has('remember'); if (Auth::attempt($credentials, $remember)) { return 'Logged in successfully with remember = ' . ($remember ? 'true' : 'false'); } return 'Login failed'; } }
Make sure your login form has a checkbox named remember for this to work.
Laravel stores a secure cookie to remember the user, which lasts for 5 years by default.
Remember me should be used carefully on public or shared computers for security.
"Remember me" keeps users logged in across browser sessions.
Use Auth::attempt with a second boolean parameter to enable it.
Always balance convenience with security when using this feature.