Skip to content
Bladewell

<x-widget.toast>

Toast Blade component for Laravel and Livewire

Notifications that appear in a corner and close themselves. Show them from a controller with a session flash, or from JavaScript. From Livewire, dispatch a toast event; flashes survive wire:navigate.

php artisan bladewell:add toast
Also adds
Nothing else. It stands alone.
Works with
Laravel 12 and 13, Livewire 3 and 4, Tailwind CSS 4.1+, PHP 8.3+
Guides
Two-factor authentication screens for Laravel Fortify · Passkey sign-in for Laravel with Fortify · Real-time notification bell with Laravel Reverb · AI agent actions with Approve and Deny in Laravel · Livewire multi-step form with validation per step · Toast notifications in Laravel and Livewire · Livewire file upload with progress and drag and drop

Usage

In your layout

Once, just before </body>. Toasts appear top-right; set position to top-left, top-center, center, bottom-left, bottom-center or bottom-right to move them. alert-auto-close="false" keeps errors and warnings until they're dismissed, so nobody misses one; the rest still close themselves.

Blade
<x-widget.toast :alert-auto-close="false" />

From a controller

Flash a message and it shows as a toast on the next page load.

PHP
return back()->with('success', 'Profile updated.'); // or 'error', 'warning', 'info'

// For a title or another type, flash a 'toast' array.
return redirect()->route('orders.show', $order)->with('toast', [
    'type' => 'info',
    'title' => 'Order placed',
    'message' => 'We will email you when it ships.',
]);

In scripts

window.toast is available once the toast script has loaded.

JavaScript
toast.success('Profile updated.');
toast.error('Something went wrong.');
toast.warning('Your session is about to expire.');
toast.info('New version available.');

// A loading toast stays until you update or dismiss it.
const id = toast.loading('Processing payment...');
toast.update(id, 'success', 'Payment confirmed.');

// The same toast shown again while it's still up (same kind, title and message) isn't repeated: the one showing
// counts it (×2) and returns its id. merge: false always gives a toast of its own, for code that keeps its id.
const saved = toast.success('Saved.', { merge: false });

// An action, like Undo: the toast stays until it's used or dismissed, and goes once it's used.
toast.success('Invoice deleted.', { action: { label: 'Undo', onClick: () => restoreInvoice(42) } });

toast.dismiss(id); // one toast
toast.dismiss();   // all of them

From livewire

From a Livewire action, dispatch a toast event: it shows straight away, no page load needed.

PHP
$this->dispatch('toast', type: 'success', message: 'Profile updated.');

// A title, or a different auto-close (in ms, or false to keep it until dismissed), go along the same way.
$this->dispatch('toast', type: 'warning', title: 'Almost full', message: 'You have used 90% of your storage.', autoClose: false);

// A session flash still works when the action redirects, wire:navigate included; it shows once, Back and Forward too.
session()->flash('success', 'Order placed.');
$this->redirect(route('orders.index'), navigate: true);

Examples

Try it

data-toast names the kind of toast and data-toast-message what it says: a click shows it, with no script. data-toast="dismiss" clears them all. A loading toast that turns into another needs your own script, like the one beside this. Needs <x-widget.toast /> once in your layout; see Usage.

Show code
Blade
<div class="flex flex-wrap gap-2">
    <button type="button" class="bg-field rounded-full px-4 py-2 text-sm" data-toast="success" data-toast-message="Profile updated.">Success</button>
    <button type="button" class="bg-field rounded-full px-4 py-2 text-sm" data-toast="error" data-toast-message="Something went wrong.">Error</button>
    <button type="button" class="bg-field rounded-full px-4 py-2 text-sm" data-toast="warning" data-toast-message="Your session is about to expire.">Warning</button>
    <button type="button" class="bg-field rounded-full px-4 py-2 text-sm" data-notify="loading">Loading, then success</button>
    <button type="button" class="text-foreground rounded-full px-4 py-2 text-sm underline underline-offset-4" data-toast="dismiss">Dismiss all</button>
</div>
JavaScript, in your own JS file
// A loading toast stays until you update it, e.g. when the request finishes.
document.addEventListener('click', (event) => {
    if (event.target.closest('[data-notify="loading"]')) {
        const id = toast.loading('Processing payment...');
        setTimeout(() => toast.update(id, 'success', 'Payment confirmed.'), 2000);
    }
});

Props

Other attributes, such as autocomplete or data-*, are passed through to the element. class styles the component's outer wrapper.

<x-widget.toast>

Prop Default Description
position 'top-right' Where toasts appear: top-left, top-center, top-right, center, bottom-left, bottom-center or bottom-right.
auto-close 3000 Milliseconds before a toast closes itself; false keeps it until dismissed. The rest of these props are defaults too: a single toast can change them in its options.
alert-auto-close null The same, for error and warning toasts only (the ones read out at once). false keeps them until dismissed, so a slow reader or a screen magnifier doesn't miss them. Unset, they follow autoClose.
show-progress true A bar along the bottom that shows the time left before it closes.
pause-on-hover true Holds the timer while the pointer is over a toast.
pause-on-focus-loss true Holds the timer while the window is in the background or the tab is hidden.
dismiss-all-label 'Dismiss all' The button above the stack, while two or more toasts are up (three on a phone), that closes them all.

Accessibility

The example above is checked with axe-core against the WCAG 2.2 A and AA rules, in the light theme and the dark one, both as the page draws and with each popover, dialog, toast and tooltip opened, on every change. A change that fails can't be merged. Where axe can't decide, such as contrast on SVG text, the test measures the colours itself instead of letting it pass.

Automated checks can't judge everything: how it sounds in a screen reader, and how it feels to use from the keyboard, still need a person. Check those on your own pages too.

Source

What bladewell:add toast writes to your app with the default namespaces. Prefer to copy by hand? Take these files, plus the ones from the components it also adds , and the theme and base CSS.

resources/views/components/widget/toast/index.blade.php Show
index.blade.php
resources/js/widget/toast/index.js Show
index.js