Complete the code to send the email verification notification in a Laravel user model.
public function sendEmailVerificationNotification()
{
$this->[1](new \Illuminate\Auth\Notifications\VerifyEmail());
}In Laravel, the notify method is used to send notifications like email verification.
Complete the middleware registration to require email verification in routes.
Route::middleware(['auth', '[1]'])->group(function () { Route::get('/dashboard', function () { return view('dashboard'); }); });
The middleware named verified ensures the user has verified their email before accessing the route.
Fix the error in the email verification route definition by completing the missing method.
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');
The fulfill method on the EmailVerificationRequest marks the user's email as verified.
Fill both blanks to create a controller method that resends the email verification notification.
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!');
}The method hasVerifiedEmail checks if the user already verified their email. The notify method sends the verification notification.
Fill all three blanks to define a route that sends the email verification notification when requested.
Route::post('/email/verification-notification', function (Request $request) { $request->user()->[1](); return back()->with('[2]', '[3]'); })->middleware(['auth', 'throttle:6,1'])->name('verification.send');
The sendEmailVerificationNotification method sends the verification notification. The flash message uses key message and value Verification link sent! to inform the user.