Bird
Raised Fist0
Laravelframework~10 mins

Email verification in Laravel - Interactive Code Practice

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

Complete the code to send the email verification notification in a Laravel user model.

Laravel
public function sendEmailVerificationNotification()
{
    $this->[1](new \Illuminate\Auth\Notifications\VerifyEmail());
}
Drag options to blanks, or click blank then click option'
Anotify
Bmail
Csend
Ddispatch
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'send' instead of 'notify' causes an error because 'send' is not a method on the user model.
Using 'mail' or 'dispatch' are not correct methods for sending notifications.
2fill in blank
medium

Complete the middleware registration to require email verification in routes.

Laravel
Route::middleware(['auth', '[1]'])->group(function () {
    Route::get('/dashboard', function () {
        return view('dashboard');
    });
});
Drag options to blanks, or click blank then click option'
Aauth.email
BemailVerified
Cverified
DcheckEmail
Attempts:
3 left
💡 Hint
Common Mistakes
Using middleware names that do not exist causes a 404 or middleware not found error.
Using 'auth.email' or 'checkEmail' are not default middleware names.
3fill in blank
hard

Fix the error in the email verification route definition by completing the missing method.

Laravel
use Illuminate\Foundation\Auth\EmailVerificationRequest;

Route::get('/email/verify/{id}/{hash}', function (EmailVerificationRequest $request) {
    $request->[1]();
    return redirect('/dashboard');
})->middleware(['auth', 'signed'])->name('verification.verify');
Drag options to blanks, or click blank then click option'
Aconfirm
Bfulfill
Ccheck
Dvalidate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'confirm' or 'validate' will cause method not found errors.
Using 'check' is not a valid method on EmailVerificationRequest.
4fill in blank
hard

Fill both blanks to create a controller method that resends the email verification notification.

Laravel
public function resend(Request $request)
{
    if ($request->user()->[1]()) {
        return redirect()->route('dashboard');
    }

    $request->user()->[2](new \Illuminate\Auth\Notifications\VerifyEmail());

    return back()->with('message', 'Verification link sent!');
}
Drag options to blanks, or click blank then click option'
AhasVerifiedEmail
Bnotify
CsendEmailVerificationNotification
Dverified
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'verified' instead of 'hasVerifiedEmail' causes logic errors.
Using 'sendEmailVerificationNotification' directly instead of 'notify' causes errors.
5fill in blank
hard

Fill all three blanks to define a route that sends the email verification notification when requested.

Laravel
Route::post('/email/verification-notification', function (Request $request) {
    $request->user()->[1]();
    return back()->with('[2]', '[3]');
})->middleware(['auth', 'throttle:6,1'])->name('verification.send');
Drag options to blanks, or click blank then click option'
AsendEmailVerificationNotification
Bmessage
CVerification link sent!
Dnotify
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'notify' instead of 'sendEmailVerificationNotification' causes errors because it requires an argument.
Using wrong flash message keys or missing the message text causes no feedback to user.

Practice

(1/5)
1. What is the main purpose of email verification in Laravel?
easy
A. To reset the user's password automatically
B. To delete unverified user accounts immediately
C. To log the user out after registration
D. To confirm a user's email address for security and trust

Solution

  1. Step 1: Understand email verification purpose

    Email verification ensures the user owns the email they provided.
  2. Step 2: Identify security benefits

    This process improves security and trust by confirming email validity.
  3. Final Answer:

    To confirm a user's email address for security and trust -> Option D
  4. Quick Check:

    Email verification = Confirm email ownership [OK]
Hint: Email verification confirms user email ownership [OK]
Common Mistakes:
  • Confusing email verification with password reset
  • Thinking it logs out users automatically
  • Assuming it deletes accounts immediately
2. Which interface must the User model implement to enable email verification in Laravel?
easy
A. Illuminate\Contracts\Auth\MustVerifyEmail
B. Illuminate\Contracts\Auth\Authenticatable
C. Illuminate\Contracts\Auth\CanResetPassword
D. Illuminate\Contracts\Auth\Access\Authorizable

Solution

  1. Step 1: Identify the required interface for email verification

    Laravel requires the User model to implement MustVerifyEmail to enable verification.
  2. Step 2: Confirm the correct namespace and interface

    The interface is Illuminate\Contracts\Auth\MustVerifyEmail.
  3. Final Answer:

    Illuminate\Contracts\Auth\MustVerifyEmail -> Option A
  4. Quick Check:

    User model implements MustVerifyEmail [OK]
Hint: Use MustVerifyEmail interface on User model [OK]
Common Mistakes:
  • Using Authenticatable instead of MustVerifyEmail
  • Confusing with password reset interfaces
  • Missing the correct namespace
3. Given this route setup in Laravel:
Route::middleware(['auth', 'verified'])->get('/dashboard', function () {
    return 'Welcome to your dashboard!';
});
What happens if a logged-in user tries to access /dashboard without verifying their email?
medium
A. They are redirected to the email verification notice page
B. They see the dashboard content immediately
C. They get a 404 Not Found error
D. They are logged out automatically

Solution

  1. Step 1: Analyze middleware effects

    The 'verified' middleware checks if the user's email is verified before allowing access.
  2. Step 2: Determine behavior for unverified users

    If not verified, Laravel redirects them to the verification notice page.
  3. Final Answer:

    They are redirected to the email verification notice page -> Option A
  4. Quick Check:

    'verified' middleware redirects unverified users [OK]
Hint: Middleware 'verified' redirects unverified users [OK]
Common Mistakes:
  • Assuming unverified users see dashboard content
  • Expecting a 404 error instead of redirect
  • Thinking users get logged out automatically
4. Consider this User model snippet:
class User extends Authenticatable
{
    // Missing implementation here
}
Why might email verification fail to work properly with this model?
medium
A. Because the model does not use the Notifiable trait
B. Because the model does not implement MustVerifyEmail interface
C. Because the model lacks a 'verified' attribute
D. Because the model extends Authenticatable instead of Model

Solution

  1. Step 1: Check interface implementation

    Email verification requires the User model to implement MustVerifyEmail interface.
  2. Step 2: Identify missing implementation

    The snippet lacks this interface, so verification won't trigger properly.
  3. Final Answer:

    Because the model does not implement MustVerifyEmail interface -> Option B
  4. Quick Check:

    Missing MustVerifyEmail causes verification failure [OK]
Hint: Implement MustVerifyEmail to enable verification [OK]
Common Mistakes:
  • Thinking extending Authenticatable is wrong
  • Assuming 'verified' attribute is required manually
  • Believing Notifiable trait controls verification
5. You want to customize the email verification process to send a verification email immediately after user registration. Which Laravel feature should you use to trigger this email automatically?
hard
A. Override the User model's boot method to send the email
B. Manually call the sendEmailVerificationNotification method in the controller
C. Use the Registered event and listen to it to send the verification email
D. Add a middleware to send the email on every request

Solution

  1. Step 1: Identify Laravel's event system for registration

    Laravel fires a Registered event after user registration.
  2. Step 2: Use event listener to send verification email

    Listening to Registered event allows sending the verification email automatically.
  3. Final Answer:

    Use the Registered event and listen to it to send the verification email -> Option C
  4. Quick Check:

    Registered event triggers verification email [OK]
Hint: Listen to Registered event to send verification email [OK]
Common Mistakes:
  • Calling sendEmailVerificationNotification manually in controller
  • Overriding boot method unnecessarily
  • Using middleware to send email on every request
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard