· yebor974 · Advanced Techniques, Tutorials
Filament Email Verification: Leveraging Laravel’s Event System
Learn how to enhance Filament email verification by leveraging Laravel's event system. Create custom listeners for user workflows like Stripe integration.

In this tutorial, we'll explore how to trigger an event when a user's email is verified in a Filament application. While this is primarily a Laravel concept, Filament fully supports and integrates with Laravel's powerful event and listener system. You'll see how to apply this to Filament projects seamlessly.
We’ll cover:
- Creating a listener for the email verification event,
- Triggering actions such as Stripe registration or newsletter subscription,
- Testing the event with
Event::fake
, - Extending the logic to other events like user registration or login.
By the end, you'll understand how to leverage Laravel's event system in your FilamentPHP apps for advanced user workflows.
To set up your project for enabling email verification on panel, you can check the first step of this article.
Verified
Event
Step 1: Create a Listener for the Laravel emits the Illuminate\Auth\Events\Verified
event when a user successfully verifies their email. Here's how to hook into it.
1.1 Generate the Listener
Run the following command to create a new listener:
php artisan make:listener HandleUserEmailVerified
This command will create a file in App\Listeners
folder:
namespace App\Listeners;
use Illuminate\Auth\Events\Verified;
class HandleUserEmailVerified
{
/**
* Handle the event.
*
* @param \Illuminate\Auth\Events\Verified $event
* @return void
*/
public function handle(Verified $event)
{
///
}
}
1.2 Implement the Listener
Update the listener to perform actions after email verification, for example :
namespace App\Listeners;
use Illuminate\Auth\Events\Verified;
class HandleUserEmailVerified
{
/**
* Handle the event.
*
* @param \Illuminate\Auth\Events\Verified $event
* @return void
*/
public function handle(Verified $event)
{
$user = $event->user;
// Example: Create a Stripe account
if (!$user->stripe_id) {
$this->createStripeAccount($user);
}
// Example: Subscribe to a newsletter
$this->subscribeToNewsletter($user);
}
protected function createStripeAccount($user)
{
// Logic to integrate with Stripe API
}
protected function subscribeToNewsletter($user)
{
// Logic to integrate with a mailing list API
}
}
Verified
Event
Step 2: Register the Listener for the If you're using Laravel 10 or later, Laravel can auto-discover event-listener mappings. So this step may not always be required, but keeping it explicit helps with debugging.
namespace App\Providers;
use Illuminate\Auth\Events\Verified;
use App\Listeners\HandleUserEmailVerified;
class EventServiceProvider extends ServiceProvider
{
protected $listen = [
Verified::class => [
HandleUserEmailVerified::class,
],
];
}
Event::fake
Step 3: Test the Listener with Before using this in production, ensure everything works as expected. Laravel provides a helpful testing utility to fake events and assert their behavior.
Here’s a test example:
namespace Tests\Feature;
use Illuminate\Auth\Events\Verified;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Event;
use Tests\TestCase;
use App\Models\User;
class EmailVerificationTest extends TestCase
{
use RefreshDatabase;
/** @test */
public function it_dispatches_verified_event_after_email_verification()
{
Event::fake();
$user = User::factory()->unverified()->create();
$user->markEmailAsVerified();
// Assert the Verified event was dispatched
Event::assertDispatched(Verified::class, function ($event) use ($user) {
return $event->user->is($user);
});
}
}
Step 4: Applying the concept in FilamentPHP
Why This Matters in Filament
Filament is built on Laravel, meaning you can use Laravel's event system in your Filament-powered applications. For example, when managing a User Resource, you can leverage the same listener to perform actions after email verification.
You could:
- Add custom hooks in Filament tables or forms,
- Use Filament notifications to display messages when an event is triggered,
- Extend user workflows directly within the Filament admin panel.
Step 5: Extending the Principle
Registered
Event: The Illuminate\Auth\Events\Registered
event fires after a new user is created. This is useful for:
- Sending a welcome email,
- Assigning default roles,
- Creating a related profile or team entry.
Example listener:
namespace App\Listeners;
use Illuminate\Auth\Events\Registered;
class HandleUserRegistered
{
public function handle(Registered $event)
{
$user = $event->user;
// Assign a default role
$user->assignRole('default');
}
}
Login
Event: The Illuminate\Auth\Events\Login
event fires upon user login. Use it to:
- Log user activity,
- Update a "last login" timestamp,
- Sync data with an external system.
Example listener:
namespace App\Listeners;
use Illuminate\Auth\Events\Login;
class HandleUserLogin
{
public function handle(Login $event)
{
$user = $event->user;
// Update last login time
$user->update(['last_login_at' => now()]);
}
}
Conclusion
By using Laravel's event system into your Filament projects, you can create robust workflows tailored to user actions. Whether it's email verification, registration, or login, the possibilities are endless.