0
0
Laravelframework~10 mins

Remember me functionality in Laravel - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to enable the 'remember me' feature in Laravel's login method.

Laravel
Auth::attempt(['email' => $email, 'password' => $password], [1]);
Drag options to blanks, or click blank then click option'
Afalse
Bnull
C'remember'
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string instead of a boolean.
Omitting the second argument entirely.
2fill in blank
medium

Complete the Blade template checkbox input to allow users to select 'remember me'.

Laravel
<input type="checkbox" name="[1]" id="remember"> <label for="remember">Remember Me</label>
Drag options to blanks, or click blank then click option'
Aremember
BrememberUser
Cremember_me
Dremember_me_checkbox
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different name that Laravel does not recognize.
Forgetting to add the checkbox input.
3fill in blank
hard

Fix the error in the middleware to check if the user is authenticated with 'remember me'.

Laravel
if (Auth::[1]()) {
    // User is authenticated
}
Drag options to blanks, or click blank then click option'
AcheckRemembered
Bcheck
CviaRemember
DcheckIfRemembered
Attempts:
3 left
💡 Hint
Common Mistakes
Using check() which doesn't distinguish remember me.
Using non-existent methods like checkRemember.
4fill in blank
hard

Fill both blanks to correctly set the 'remember me' cookie duration and name in Laravel's config.

Laravel
'remember' => [
    'expire' => [1],
    'name' => '[2]',
],
Drag options to blanks, or click blank then click option'
A43200
B3600
Cremember_web
Dremember_token
Attempts:
3 left
💡 Hint
Common Mistakes
Setting expiration too short or too long.
Using incorrect cookie names like remember_token (that's the DB field).
5fill in blank
hard

Fill all three blanks to complete the login controller method that handles 'remember me' correctly.

Laravel
public function login(Request $request) {
    $credentials = $request->only('email', 'password');
    $remember = $request->has('[1]');
    if (Auth::attempt($credentials, [2])) {
        return redirect()->intended('[3]');
    }
    return back()->withErrors(['email' => 'Invalid credentials']);
}
Drag options to blanks, or click blank then click option'
Aremember
B$remember
C/dashboard
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong checkbox name.
Passing a string or literal instead of the $remember variable to Auth::attempt.
Redirecting to wrong URL.