filament/notifications
Add sleek, real-time notifications to your Filament admin panel. Create toast alerts and in-app messages with customizable titles, bodies, actions, icons, colors, and durations. Send notifications from your Laravel app and keep users informed without leaving the dashboard.
Installation
composer require filament/notifications
Publish the config (if needed):
php artisan vendor:publish --provider="Filament\Notifications\NotificationsServiceProvider"
Basic Usage
Add the HasNotifications trait to your Livewire component:
use Filament\Notifications\Concerns\HasNotifications;
class MyComponent extends Component
{
use HasNotifications;
public function mount()
{
$this->notify('Success', 'Your action was completed!');
}
First Notification Trigger a notification in a Livewire action:
public function save()
{
// ... save logic
$this->notify('Success', 'Record saved successfully!');
}
View the Notifications The package automatically renders notifications in your Livewire component's view. No additional Blade template is required.
Conditional Notifications
if ($user->save()) {
$this->notify('Success', 'Profile updated!');
} else {
$this->notify('Error', 'Failed to update profile.', type: 'error');
}
Persistent Notifications
Use persistent: true for notifications that should not auto-dismiss:
$this->notify('Info', 'This will stay until dismissed.', persistent: true);
Custom Icons Pass an icon name (from Heroicons):
$this->notify('Warning', 'Something went wrong.', icon: 'heroicon-o-exclamation-circle');
Queueing Notifications
For async processing, use queue():
$this->notify('Processing', 'Your request is being handled...', queue: true);
Notification Groups Group related notifications (e.g., form validation errors):
$this->notifyGroup('validation', [
'name' => 'The name field is required.',
'email' => 'The email must be valid.',
]);
Customizing Appearance
Override the default notification view in resources/views/vendor/filament/notifications/notification.blade.php.
$this->notifications in Blade templates to manually render notifications.document.addEventListener('filament-notification', (e) => {
console.log(e.detail);
});
assertSeeInNotifications() in Pest/Laravel tests:
$this->assertSeeInNotifications('Success', 'Record saved!');
Auto-Dismiss Delay Notifications auto-dismiss after 5 seconds by default. Override via config:
'auto_dismiss' => 3, // seconds
Queueing Issues
Ensure your queue worker is running if using queue: true. Notifications may not appear immediately.
Styling Conflicts
Custom CSS may override Filament’s default styles. Use !important sparingly or inspect the generated classes.
Persistent Notifications
Persistent notifications (persistent: true) require manual dismissal. Ensure your UI includes a close button.
Livewire Re-renders
Notifications may flicker if the component re-renders frequently. Use wire:ignore on the notification container if needed.
config/filament.php don’t apply:
php artisan config:clear
Custom Notification Types
Extend the Filament\Notifications\Notification class to add custom logic:
class CustomNotification extends Notification
{
public function __construct(public string $title, public string $message)
{
$this->title = $title;
$this->message = $message;
}
public function getIcon(): string
{
return 'heroicon-o-bell';
}
}
Use via:
$this->notify(new CustomNotification('Title', 'Message'));
Override Default Views Publish and modify the notification Blade views:
php artisan vendor:publish --tag="filament-notifications-views"
Add Animation
Extend the Tailwind CSS classes in resources/css/app.css:
.filament-notification-enter-active {
animation: slide-in 0.3s ease-out;
}
Localization Translate notification messages via Laravel’s localization system:
$this->notify(__('filament::notifications.success'), __('filament::notifications.saved'));
How can I help you explore Laravel packages today?