Skip to main content
Version: 2.x

Sending notifications

To start, make sure the package is installed - @livewire('notifications') should be in your Blade layout somewhere.

Notifications are sent using a Notification object that's constructed through a fluent API. Calling the send() method on the Notification object will dispatch the notification and display it in your application. As the session is used to flash notifications, they can be sent from anywhere in your code, including JavaScript, not just Livewire components.

<?php

namespace App\Http\Livewire;

use Filament\Notifications\Notification; // [tl! focus]
use Livewire\Component;

class EditPost extends Component
{
public function save(): void
{
// ...

Notification::make() // [tl! focus:start]
->title('Saved successfully')
->success()
->send(); // [tl! focus:end]
}
}

Notification

Title

The main message of the notification is shown in the title. You can set the title as follows:

use Filament\Notifications\Notification;

Notification::make()
->title('Saved successfully') // [tl! focus]
->send();

Or with JavaScript:

new Notification()
.title('Saved successfully') // [tl! focus]
.send()

Markdown text will automatically be rendered if passed to the title.

Icon

Optionally, a notification can have an icon that's displayed in front of its content. You may also set a color for the icon, which defaults to the secondary color specified in your tailwind.config.js file. The icon can be the name of any Blade component. By default, the Blade Heroicons v1 package is installed, so you may use the name of any Heroicons v1 out of the box. However, you may create your own custom icon components or install an alternative library if you wish.

use Filament\Notifications\Notification;

Notification::make()
->title('Saved successfully')
->icon('heroicon-o-document-text') // [tl! focus:start]
->iconColor('success') // [tl! focus:end]
->send();

Or with JavaScript:

new Notification()
.title('Saved successfully')
.icon('heroicon-o-document-text') // [tl! focus:start]
.iconColor('success') // [tl! focus:end]
.send()

Notification with icon

Notifications often have a status like success, warning or danger. Instead of manually setting the corresponding icons and colors, there's a status() method which you can pass the status. You may also use the dedicated success(), warning() and danger() methods instead. So, cleaning up the above example would look like this:

use Filament\Notifications\Notification;

Notification::make()
->title('Saved successfully')
->success() // [tl! focus]
->send();

Or with JavaScript:

new Notification()
.title('Saved successfully')
.success() // [tl! focus]
.send()

Success, warning and danger notifications

Duration

By default, notifications are shown for 6 seconds before they're automatically closed. You may specify a custom duration value in milliseconds as follows:

use Filament\Notifications\Notification;

Notification::make()
->title('Saved successfully')
->success()
->duration(5000) // [tl! focus]
->send();

Or with JavaScript:

new Notification()
.title('Saved successfully')
.success()
.duration(5000) // [tl! focus]
.send()

If you prefer setting a duration in seconds instead of milliseconds, you can do so:

use Filament\Notifications\Notification;

Notification::make()
->title('Saved successfully')
->success()
->seconds(5) // [tl! focus]
->send();

Or with JavaScript:

new Notification()
.title('Saved successfully')
.success()
.seconds(5) // [tl! focus]
.send()

You might want some notifications to not automatically close and require the user to close them manually. This can be achieved by making the notification persistent:

use Filament\Notifications\Notification;

Notification::make()
->title('Saved successfully')
->success()
->persistent() // [tl! focus]
->send();

Or with JavaScript:

new Notification()
.title('Saved successfully')
.success()
.persistent() // [tl! focus]
.send()

Body

Additional notification text can be shown in the body. Similar to the title, it supports Markdown:

use Filament\Notifications\Notification;

Notification::make()
->title('Saved successfully')
->success()
->body('Changes to the **post** have been saved.') // [tl! focus]
->send();

Or with JavaScript:

new Notification()
.title('Saved successfully')
.success()
.body('Changes to the **post** have been saved.') // [tl! focus]
.send()

Notification with Markdown body

Actions

Notifications support actions that render a button or link which may open a URL or emit a Livewire event. Actions will render as link by default, but you may configure it to render a button using the button() method. Actions can be defined as follows:

use Filament\Notifications\Actions\Action; // [tl! focus]
use Filament\Notifications\Notification;

Notification::make()
->title('Saved successfully')
->success()
->body('Changes to the **post** have been saved.')
->actions([ // [tl! focus:start]
Action::make('view')
->button(),
Action::make('undo')
->color('secondary'),
]) // [tl! focus:end]
->send();

Or with JavaScript:

new Notification()
.title('Saved successfully')
.success()
.body('Changes to the **post** have been saved.')
.actions([ // [tl! focus:start]
new NotificationAction('view')
.button(),
new NotificationAction('undo')
.color('secondary'),
]) // [tl! focus:end]
.send()

Notification with actions

Opening URLs

If clicking on an action should open a URL, optionally in a new tab, you can do so:

use Filament\Notifications\Actions\Action;
use Filament\Notifications\Notification;

Notification::make()
->title('Saved successfully')
->success()
->body('Changes to the **post** have been saved.')
->actions([
Action::make('view')
->button()
->url(route('posts.show', $post), shouldOpenInNewTab: true) // [tl! focus]
Action::make('undo')
->color('secondary'),
])
->send();

Or with JavaScript:

new Notification()
.title('Saved successfully')
.success()
.body('Changes to the **post** have been saved.')
.actions([
new NotificationAction('view')
.button()
.url('/view') // [tl! focus:start]
.openUrlInNewTab(), // [tl! focus:end]
new NotificationAction('undo')
.color('secondary'),
])
.send()

Emitting events

Sometimes you want to execute additional code when a notification action is clicked. This can be achieved by setting a Livewire event which should be emitted on clicking the action. You may optionally pass an array of data, which will be available as parameters in the event listener on your Livewire component:

use Filament\Notifications\Actions\Action;
use Filament\Notifications\Notification;

Notification::make()
->title('Saved successfully')
->success()
->body('Changes to the **post** have been saved.')
->actions([
Action::make('view')
->button()
->url(route('posts.show', $post), shouldOpenInNewTab: true),
Action::make('undo')
->color('secondary')
->emit('undoEditingPost', [$post->id]), // [tl! focus]
])
->send();

You can also emitSelf, emitUp and emitTo:

Action::make('undo')
->color('secondary')
->emitSelf('undoEditingPost', [$post->id]) // [tl! focus]

Action::make('undo')
->color('secondary')
->emitUp('undoEditingPost', [$post->id]) // [tl! focus]

Action::make('undo')
->color('secondary')
->emitTo('another_component', 'undoEditingPost', [$post->id]) // [tl! focus]

Or with JavaScript:

new Notification()
.title('Saved successfully')
.success()
.body('Changes to the **post** have been saved.')
.actions([
new NotificationAction('view')
.button()
.url('/view')
.openUrlInNewTab(),
new NotificationAction('undo')
.color('secondary')
.emit('undoEditingPost'), // [tl! focus]
])
.send()

Similarly, emitSelf, emitUp and emitTo are also available:

new NotificationAction('undo')
.color('secondary')
.emitSelf('undoEditingPost') // [tl! focus]

new NotificationAction('undo')
.color('secondary')
.emitUp('undoEditingPost') // [tl! focus]

new NotificationAction('undo')
.color('secondary')
.emitTo('another_component', 'undoEditingPost') // [tl! focus]

Closing notifications

After opening a URL or emitting an event from your action, you may want to close the notification right away:

use Filament\Notifications\Actions\Action;
use Filament\Notifications\Notification;

Notification::make()
->title('Saved successfully')
->success()
->body('Changes to the **post** have been saved.')
->actions([
Action::make('view')
->button()
->url(route('posts.show', $post), shouldOpenInNewTab: true),
Action::make('undo')
->color('secondary')
->emit('undoEditingPost', [$post->id])
->close(), // [tl! focus]
])
->send();

Or with JavaScript:

new Notification()
.title('Saved successfully')
.success()
.body('Changes to the **post** have been saved.')
.actions([
new NotificationAction('view')
.button()
.url('/view')
.openUrlInNewTab(),
new NotificationAction('undo')
.color('secondary')
.emit('undoEditingPost')
.close(), // [tl! focus]
])
.send()

Using the JavaScript objects

The JavaScript objects (Notification and NotificationAction) are assigned to window.Notification and window.NotificationAction, so they are available in on-page scripts.

You may also import them in a bundled JavaScript file:

import { Notification, NotificationAction } from '../../vendor/filament/notifications/dist/module.esm'

// ...