· yebor974 · Case Studies, Tutorials, Advanced Techniques

How to send Filament database notifications to a specific queue

Learn how to control the queue for Filament database notifications in Laravel instead of using the default queue.

Filament PHP and Laravel database notifications with queue control, using toDatabase()->onQueue() for efficient background processing

When working with Filament\Notifications\Notification, sending database notifications with sendToDatabase() is super convenient. But what if you want to control which queue these notifications are dispatched to?

At first glance, this looks tricky, Filament doesn’t expose a queue configuration option directly. But the good news is: you can still take full advantage of Laravel’s queue system.

Default behavior for Filament notifications on database

The usual Filament way looks like this:

use Filament\Notifications\Notification;

Notification::make()
    ->title("Your request has been processed")
    ->body("Some details about the request")
    ->sendToDatabase($user);

What happens under the hood:

  • Filament calls $user->notify($this->toDatabase()).
  • toDatabase() creates a Filament\Notifications\DatabaseNotification, which extends Laravel’s Notification, implements ShouldQueue, and uses the Queueable trait.
  • That means the notification goes into the queue defined by your QUEUE_CONNECTION (database, redis, etc.), but you cannot specify which queue name this way.

How to control the queue: Using toDatabase() + onQueue()

Instead of sendToDatabase(), grab the notification instance with toDatabase() and apply onQueue():

use Filament\Notifications\Notification as FilamentNotification;

$databaseNotification = FilamentNotification::make()
    ->title("Your request has been processed")
    ->body("Some details about the request")
    ->toDatabase()              // returns a DatabaseNotification (Laravel Notification)
    ->onQueue('notifications'); // from Queueable trait

$user->notify($databaseNotification);

Or, in a single line:

$user->notify(
    FilamentNotification::make()
        ->title("Your request has been processed")
        ->body("Some details about the request")
        ->toDatabase()
        ->onQueue('notifications')
);

This way you keep the simplicity of Filament’s fluent API and you get fine-grained queue control.

Multiple users example

If you need to notify multiple users on the same queue:

$notif = FilamentNotification::make()
    ->title("Your request has been processed")
    ->body("Some details about the request")
    ->toDatabase()
    ->onQueue('notifications');

foreach ($users as $user) {
    $user->notify($notif); // reuses the same notification instance
}

Conclusion

If you just want to send database notifications, Filament’s sendToDatabase() is perfect.

But if you need queue control, switch to toDatabase()->onQueue('...'). That way you stay fully in the Filament ecosystem, so your notifications are correctly stored and displayed in your Filament panels, while still taking advantage of Laravel’s queue flexibility.

🙏 Thanks to @obaume for reaching out on this topic. His question made me dive deeper into Filament notifications and discover this approach!

💡 Community Idea: Currently, sendToDatabase() doesn’t allow specifying a queue. If this article gets enough likes or shares, I’ll consider proposing a Pull Request to Filament to add this feature—making queue management even easier for everyone!

Avatar of yebor974
yebor974
Freelance - French IT Engineer passionate about Laravel and Filament PHP, creating innovative solutions to simplify web development.
React
Share post

Stay ahead in the Filament Mastery adventure

Join our community of Filament PHP enthusiasts! Get exclusive tips, tutorials, and updates delivered straight to your inbox.