F
Filament7mo ago
mrvn

Customize VerifyEmail template and other login related emails

Overriding sendEmailVerificationNotification() in User model doesnt work as filament creates the notification directly instead of accessing the user. Could this be a bug? How to change the template and arguments then?
4 Replies
Povilas K
Povilas K7mo ago
Not sure about Verification email specifically, though, haven't tried, but maybe the same logic would work
mrvn
mrvnOP7mo ago
Thank you, I will check on that
putraprima
putraprima5mo ago
i tried this logic but the first email send by filament always the default one but if we click the send email again button it will send the customized template any hints of how to fix it ? But i can confirm that the custom reset password email message works perfectly Oooh nevermind guys i got it : 1. Povilas tutorial is correct it works perfectly 2. To implement custom email message on registration you should also Extend the registration page in filament vendor 3. Create custom message for the first email when user register 4. Also create custom page for email verification prompt with custom email message so the user Here is some code snippet panel provider
return $panel
->default()
->id('user')
->path('user')
->login()
->registration(Register::class)
->emailVerification(EmailVerificationPrompt::class)
->passwordReset(RequestPasswordReset::class)
->sidebarWidth('16rem')
->colors([
'primary' => Color::Indigo,
])
return $panel
->default()
->id('user')
->path('user')
->login()
->registration(Register::class)
->emailVerification(EmailVerificationPrompt::class)
->passwordReset(RequestPasswordReset::class)
->sidebarWidth('16rem')
->colors([
'primary' => Color::Indigo,
])
Custom register page
<?php

namespace App\Filament\User\Pages\Auth;

use Filament\Pages\Auth\Register as AuthRegister;
use App\Notifications\VerifyEmailNotification;
use Exception;
use Filament\Facades\Filament;
use Filament\Pages\Auth\EmailVerification\EmailVerificationPrompt as BaseEmailVerificationPrompt;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Model;

class Register extends AuthRegister
{
protected function sendEmailVerificationNotification(Model $user): void
{
if (!$user instanceof MustVerifyEmail) {
return;
}

if ($user->hasVerifiedEmail()) {
return;
}

if (!method_exists($user, 'notify')) {
$userClass = $user::class;

throw new Exception("Model [{$userClass}] does not have a [notify()] method.");
}

$notification = new VerifyEmailNotification(Filament::getVerifyEmailUrl($user));

$user->notify($notification);
}
}
<?php

namespace App\Filament\User\Pages\Auth;

use Filament\Pages\Auth\Register as AuthRegister;
use App\Notifications\VerifyEmailNotification;
use Exception;
use Filament\Facades\Filament;
use Filament\Pages\Auth\EmailVerification\EmailVerificationPrompt as BaseEmailVerificationPrompt;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Model;

class Register extends AuthRegister
{
protected function sendEmailVerificationNotification(Model $user): void
{
if (!$user instanceof MustVerifyEmail) {
return;
}

if ($user->hasVerifiedEmail()) {
return;
}

if (!method_exists($user, 'notify')) {
$userClass = $user::class;

throw new Exception("Model [{$userClass}] does not have a [notify()] method.");
}

$notification = new VerifyEmailNotification(Filament::getVerifyEmailUrl($user));

$user->notify($notification);
}
}
Want results from more Discord servers?
Add your server