0
0
Laravelframework~10 mins

Authentication guards 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 check if the user is authenticated using the default guard.

Laravel
<?php
if (Auth::[1]()) {
    // User is authenticated
}
Drag options to blanks, or click blank then click option'
Acheck
Bguest
Cuser
Dattempt
Attempts:
3 left
💡 Hint
Common Mistakes
Using guest() instead of check()
Using attempt() which is for login attempts
2fill in blank
medium

Complete the code to get the currently authenticated user from the 'admin' guard.

Laravel
<?php
$user = Auth::guard('[1]')->user();
Drag options to blanks, or click blank then click option'
Aweb
Bapi
Cadmin
Dguest
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'web' guard instead of 'admin'
Using 'guest' which is not a guard name
3fill in blank
hard

Fix the error in the code to log out the user from the 'api' guard.

Laravel
<?php
Auth::guard('[1]')->[2]();
Drag options to blanks, or click blank then click option'
Aapi
Blogout
Clogin
Duser
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'login' instead of 'logout'
Not specifying the guard name
4fill in blank
hard

Fill both blanks to check if the user is a guest on the 'web' guard.

Laravel
<?php
if (Auth::guard('[1]')->[2]()) {
    // User is a guest
}
Drag options to blanks, or click blank then click option'
Aweb
Bguest
Ccheck
Dapi
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'check()' instead of 'guest()'
Using 'api' guard instead of 'web'
5fill in blank
hard

Fill all three blanks to attempt login with email and password on the 'admin' guard.

Laravel
<?php
$credentials = ['email' => $email, 'password' => $password];
if (Auth::guard('[1]')->[2]([3])) {
    // Login successful
}
Drag options to blanks, or click blank then click option'
Aadmin
Battempt
C$credentials
Dweb
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'web' guard instead of 'admin'
Using 'login' instead of 'attempt'
Passing wrong variable instead of credentials