0
0
Laravelframework~10 mins

Email verification 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 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.