Created
March 27, 2024 22:08
-
-
Save bulentsakarya/d4e228a576193ad28803d5ea27aa85b5 to your computer and use it in GitHub Desktop.
Multi Guard with Breeze and Laravel 11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected $listen = [ | |
Registered::class => [ | |
SendEmailVerificationNotification::class, | |
], | |
]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User extends Authenticatable implements MustVerifyEmail |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected function verificationUrl($notifiable) | |
{ | |
if (static::$createUrlCallback) { | |
return call_user_func(static::$createUrlCallback, $notifiable); | |
} | |
return URL::temporarySignedRoute( | |
'app.verification.verify', | |
now()->addMinutes(config('auth.verification.expire', 60)), | |
[ | |
'id' => $notifiable->getKey(), | |
'hash' => sha1($notifiable->getEmailForVerification()), | |
] | |
); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function sendEmailVerificationNotification() | |
{ | |
$this->notify(new UserVerifyEmail); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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