Core
Notifications
Pluggable notification system with multiple drivers.
Pluggable notification system with multiple drivers.
Drivers
| Driver | Class | Delivery | Requirements |
|---|---|---|---|
| Session | SessionDriver |
session()->flash() + a Livewire event (type + message only) |
None (default) |
| Livewire | LivewireEventDriver |
Livewire $dispatch() browser event with the full payload |
Frontend listener (toast container) |
| Flasher | FlasherDriver |
PHP Flasher integration | php-flasher/flasher-laravel |
| Null | NullDriver |
No-op — discards everything | None |
The session driver is the default.
Which driver for what?
| Use this driver when… | Driver |
|---|---|
| You want zero-setup feedback that survives redirects / full page loads (flash), with a basic live toast as a bonus — good default for server-rendered and redirect-after-action flows. | SessionDriver |
Your UI is the toast container and you want rich, instant toasts (title, duration, icon) without a reload. Recommended pairing with <x-wire-notifications::toast-container />. |
LivewireEventDriver |
| Your app already uses php-flasher (Toastr / Notyf / SweetAlert adapters) and you want notifications to flow into that existing UI. | FlasherDriver |
| You want to disable notifications — tests, queued/background jobs, or any context with no user to notify. | NullDriver |
Which drivers feed the toast container?
<x-wire-notifications::toast-container />is an Alpine listener on a Livewire browser event, so only event-dispatching drivers reach it:LivewireEventDriver(fulltitle/duration/icon) andSessionDriver(onlytype+message;title/durationfall back to the container defaults).FlasherDriverrenders its own UI and bypasses the container;NullDrivershows nothing.
Notification Builder
Notification is an immutable value object. Create via static factory, then send through NotificationManager.
use NyonCode\WireCore\Notifications\Notification;use NyonCode\WireCore\Notifications\NotificationManager; // Shorthand factories — create and send immediatelyNotificationManager::success('User saved');NotificationManager::error('Failed to delete'); // Build a notification, then send$notification = Notification::success('The user was successfully updated.') ->title('Record Saved'); NotificationManager::send($notification); // Full customization$notification = Notification::make('success', 'Changes saved.') ->title('Done') ->icon('check') ->duration(5000) // ms, 0 = persistent ->position('top-right') // top-right, top-left, bottom-right, bottom-left ->extra(['link' => '/details']); NotificationManager::send($notification);
Notification API
// Static factories (return a new Notification instance)Notification::make(string $type, string $message): staticNotification::success(string $message): staticNotification::error(string $message): staticNotification::warning(string $message): staticNotification::info(string $message): static // Fluent immutable modifiers (each returns a new instance)->title(?string $title): static->duration(?int $ms): static // auto-dismiss time, 0 = persistent->icon(?string $icon): static->position(?string $position): static->extra(array $data): static // arbitrary extra data (merged)->toArray(): array // serialize to array // Sending (via NotificationManager)NotificationManager::send(Notification $n, ?NotificationDriver $driver = null, mixed $livewire = null): voidNotificationManager::success(string $message, ...): voidNotificationManager::error(string $message, ...): voidNotificationManager::warning(string $message, ...): voidNotificationManager::info(string $message, ...): void
Usage in Actions
Action::make('save') ->action(function ($record, Action $action) { $record->save(); $action->sendSuccessNotification(); }) ->successNotification('Saved!'); // Custom notification from action$action->sendNotification( Notification::success('Done') ->title('Processed') ->duration(3000) ->icon('check'));
Usage in Components
use NyonCode\WireCore\Notifications\Concerns\InteractsWithNotifications;use NyonCode\WireCore\Notifications\Notification; class MyComponent extends Component{ use InteractsWithNotifications; public function save(): void { // ... save logic // Type shortcuts (take a message string) $this->notifySuccess('Record saved'); $this->notifyError('Save failed'); $this->notifyWarning('Careful'); $this->notifyInfo('Heads up'); // Or send a fully-built Notification $this->notify( Notification::success('Record saved')->title('Done')->duration(5000) ); }}
Usage in Forms
Forms automatically send a success notification after save() unless disabled:
Form::make() ->schema([...]) ->model(User::class) ->successMessage('User saved!') // custom message ->save(); // DisableForm::make() ->schema([...]) ->disableSuccessNotification() ->save();
Configuration
// config/wire-core.phpreturn [ 'notifications' => [ 'default' => env('WIRE_NOTIFICATIONS_DRIVER', 'session'), // session, livewire, flasher, null ],];
This config value drives the container-bound NotificationDriver (resolved by the service provider for constructor/app() injection).
Driver Resolution Order
When you call NotificationManager::send() (or its shortcuts), the driver is resolved in this order:
- Explicit driver passed to the call / component (
setNotificationDriver(), the$driverargument) - Global default set via
NotificationManager::setDefaultDriver() - Fallback: built-in
SessionDriver
Note: the static
NotificationManagerdoes not readwire-core.notifications.defaulton its own — that config only feeds the container binding. To make the configured driver the global default for the static API, bridge it once in a service provider:use NyonCode\WireCore\Notifications\Contracts\NotificationDriver;use NyonCode\WireCore\Notifications\NotificationManager;NotificationManager::setDefaultDriver(app(NotificationDriver::class));
Custom Drivers
Implement the NotificationDriver contract — its single send() method receives the notification and (optionally) the Livewire component in scope:
use NyonCode\WireCore\Notifications\Contracts\NotificationDriver;use NyonCode\WireCore\Notifications\Notification; class SlackDriver implements NotificationDriver{ public function send(Notification $notification, mixed $livewireComponent = null): void { Http::post('https://hooks.slack.com/...', [ 'text' => $notification->title . ': ' . $notification->message, ]); }}
Register it as the global default in a service provider (boot()):
use NyonCode\WireCore\Notifications\NotificationManager; NotificationManager::setDefaultDriver(new SlackDriver());
Or use it for a single component/call without changing the global default:
$this->setNotificationDriver(new SlackDriver()); // per-component (trait)NotificationManager::send($notification, new SlackDriver()); // per-call
Blade Component
Place the toast container in your layout:
<x-wire-notifications::toast-container />