Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Stevefon10's avatar

Email Verification with Laravel 11 and Filament

Hello guys, I did implement a custom registration path in my filament 3 app (no auth startup kits - but using filament breezy) where I fire the event(new Registered($user)); event. I created a listener to use the filament Filament\Notifications\Auth\VerifyEmail; class to send the verification email.

With Laravel 10, all went great and an email verification was sent properly.

Now updating to Laravel 11, I find myself with a route error stating ['verification.verify'] route don't exist.

I found out that the original Laravel SendEmailVerificationNotification listener is fired and tries to send its email with this route (that doesn't exist in my app - as filament takes care of the route naming according to the panel used). I shortcutted its launch by adding a return false to my own SendEmailVerificationNotification class but it creates confusion with the signature in the email verification link... So not enough to bypass the whole EmailVerification of Laravel. Also I am worried if in the future other listeners need to be implemented this return false feature that stops other listener to listen will bite me in the arse!

So I am looking for a way to un-dispatch a core Laravel listener with Laravel 11 as they are now automatically registered. Can't seem to find in docs or other online examples.

Thanks !

0 likes
6 replies
LaryAI's avatar
Level 58

To address the issue of the ['verification.verify'] route error and the automatic dispatching of Laravel's core listener in Laravel 11 while using Filament, you can manually override the event listener registration for the Illuminate\Auth\Events\Registered event. This will allow you to prevent Laravel's default email verification handling and use Filament's custom handling instead.

Here's how you can achieve this:

  1. Unregister the Default Listener: First, you need to unregister the default SendEmailVerificationNotification listener that Laravel automatically registers.

  2. Register Your Custom Listener: After unregistering the default listener, you can register your own listener that uses Filament's verification system.

You can do this in your EventServiceProvider or wherever you manage your event listeners. Here's an example of how you might adjust your EventServiceProvider:

<?php

namespace App\Providers;

use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use App\Listeners\CustomSendEmailVerificationNotification;

class EventServiceProvider extends ServiceProvider
{
    protected $listen = [
        // Other event listeners...
    ];

    public function boot()
    {
        parent::boot();

        // Remove the default verification notification
        \Event::listen(
            Registered::class,
            [SendEmailVerificationNotification::class, 'handle']
        );

        // Add your custom verification notification
        \Event::listen(
            Registered::class,
            [CustomSendEmailVerificationNotification::class, 'handle']
        );
    }
}
  1. Implement Your Custom Listener: Ensure that your custom listener CustomSendEmailVerificationNotification uses Filament's notification system correctly. Here's a basic structure for your custom listener:
<?php

namespace App\Listeners;

use Illuminate\Auth\Events\Registered;
use Filament\Notifications\Auth\VerifyEmail;

class CustomSendEmailVerificationNotification
{
    public function handle(Registered $event)
    {
        $user = $event->user;
        $notification = new VerifyEmail;
        $notification->toUser($user);
    }
}

This setup ensures that when a user registers, Laravel's default email verification listener is bypassed, and your custom listener using Filament's system is used instead.

Make sure to test this thoroughly to ensure that the email verification process works as expected in your application environment. This approach should help you integrate Filament's system without conflicts from Laravel's default system, especially after upgrading to Laravel 11.

Stevefon10's avatar

Thanks mr Lary. But this code did not remove the call to Laravel Event listener.

What I ended doing is to just bind my personal SendEmailVerificationNotification listener to the Laravel one in my AppServiceProvider

public function register(): void
    {
           $this->app->bind(SendEmailVerificationNotification::class, \App\Listeners\SendEmailVerificationNotification::class);
    }

And I removed my own Listener from the EventServiceProvider.

Still need to test thoroughly but so far so good. thanks

1 like
ctechdev's avatar

Hi, I have to manage your same problem and I wanted to know if there are other ways to do it, I haven't found much documentation on the matter and I've recently started using Laravel & Filament

Stevefon10's avatar

Hi, the solution I explained in my previous post did indeed fix my issue.

In AppServiceProvider.php:

    use Illuminate\Auth\Listeners\SendEmailVerificationNotification;

    public function register(): void
    {
        ...
        $this->app->bind(SendEmailVerificationNotification::class, \App\Listeners\SendEmailVerificationNotification::class);
    }

And here is my SendEmailVerificationNotification:

I hope it helps you out.

Stevefon10's avatar

I am now running into a problem as I started to use the Queue for my emails, the app language is not applied correctly for queued task and auth emails are not sent following the user locale.

I will try to see if I can set the locale for each jobs...

Stevefon10's avatar

ok I ended up doing:

  1. Adding a new Notification that will overide the Filament VerifyEmail notification, adding a $locale parameter.
  1. Modify my listeners like this:

Like this the queued email will use the correct language that was present at the time the task was generated.

1 like

Please or to participate in this conversation.