laravelopenpackages / toast
Toast notifications for Laravel: call Toast::success('Saved.') on the server and it shows in the browser, after a redirect or a full page, with optional Nitro Fusion support.
Requires
- php: ^8.3
- illuminate/session: ^13.0
- illuminate/support: ^13.0
- illuminate/view: ^13.0
Requires (Dev)
- orchestra/testbench: ^11.0
- phpunit/phpunit: ^12.0
Suggests
- nitro/fusion: Toasts raised in a #[Server] call reach the page with the call's answer.
Provides
None
Conflicts
None
Replaces
None
README
Toast notifications for Laravel. Raise one on the server, it shows in the browser:
use LaravelOpenPackages\Toast\Facades\Toast; Toast::success('Student saved.'); Toast::error('Could not save.', title: 'Error'); Toast::warning('Fee plan has no subjects.', duration: 0); // stays until dismissed Toast::info('Import queued.');
Place the container once in your layout, before </body>:
<x-toast::container />
Installation
composer require laravelopenpackages/toast
The service provider and the Toast alias register themselves.
How a toast reaches the page
A toast raised during a request is flashed to the session and shown when the next page
renders <x-toast::container />: after a redirect, or on the page the request itself returns.
From the browser, dispatch a toast event:
window.dispatchEvent(new CustomEvent('toast', { detail: { type: 'success', message: 'Copied' } })); window.LaravelToast.show({ type: 'success', message: 'Copied', title: null, duration: 4000 });
Integrations
- Nitro Fusion, detected when installed: toasts
travel as Fusion flash data instead of the session, so one raised in a
#[Server]call arrives with the call's answer. In a view,$dispatch('toast', 'success', 'Copied')raises one in the browser. Settoast.fusiontofalseto use the session only.
Messages are always shown as text, never as HTML.
Configuration
php artisan vendor:publish --tag=toast-config
| Key | Default | |
|---|---|---|
duration |
4000 |
Milliseconds on screen; 0 keeps a toast until it is dismissed (TOAST_DURATION) |
position |
top-right |
top-right, top-left, bottom-right or bottom-left (TOAST_POSITION) |
fusion |
true |
Send toasts as Fusion flash data when Fusion is installed |
The container brings its own small stylesheet, so it needs nothing from your CSS build.
php artisan vendor:publish --tag=toast-views copies the view to restyle it.
Octane
The toast manager is bound scoped, so one request's toasts never reach the next.