Skip to content

Instantly share code, notes, and snippets.

@bulentsakarya
Created March 27, 2024 22:08
Show Gist options
  • Save bulentsakarya/d4e228a576193ad28803d5ea27aa85b5 to your computer and use it in GitHub Desktop.
Save bulentsakarya/d4e228a576193ad28803d5ea27aa85b5 to your computer and use it in GitHub Desktop.
Multi Guard with Breeze and Laravel 11
protected $listen = [
Registered::class => [
SendEmailVerificationNotification::class,
],
];
class User extends Authenticatable implements MustVerifyEmail
public function toMail($notifiable)
{
return (new MailMessage)
->subject('Verify Your Email Address')
->line('To verify your account, click the link below:')
->action('Verify Email Address', $this->verificationUrl($notifiable))
->line('If you did not create an account, you can ignore this email.');
}
public function boot(): void
{
/**
* E-mail Verification
*/
VerifyEmail::toMailUsing(function ($notifiable) {
if ($notifiable->guard == 'web') { // Example 'web' guard check
return (new UserVerifyEmail)->toMail($notifiable);
} else {
// Specify the custom notification class for the other guard
return (new AdminVerifyEmail)->toMail($notifiable);
}
});
}
public function sendEmailVerificationNotification()
{
$this->notify(new UserVerifyEmail);
}
Route::middleware(['auth:web'])->prefix('app')->name('app.')->group(function () {
Route::get('/verify-email', EmailVerificationPromptController::class)->name('verification.notice');
Route::middleware(['signed', 'throttle:6,1'])->group(function () {
Route::get('/verify-email/{id}/{hash}', VerifyEmailController::class)->name('verification.verify');
});
Route::middleware('throttle:6,1')->controller(EmailVerificationNotificationController::class)->group(function () {
Route::post('/email/verification-notification', 'store')->name('verification.send');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment