Search 71 components and 72 controllers by name, category or description.
Toaster
Persistent toast stack for session flash, Turbo Streams and JavaScript notifications
Mount it once
ConceptualThis playground already mounts the viewport in its layout, which is why every button below can raise a toast without one on the page. A second viewport would fight the first over window.toaster, so the setup is shown rather than rendered.
Once, in the layout
One tag before </body> is the whole setup.
Survives navigation
It ships data-turbo-permanent, so the stack outlives a Drive visit.
Order does not matter
A toast fired before it connects is buffered and drained on connect.
<!DOCTYPE html>
<html lang="en">
<head>...</head>
<body>
{{ $slot }}
<hw:toaster />
</body>
</html>
From a session flash
The viewport reads the session itself. toast, success, error, warning, info and errors are read in that order and the first usable message wins — so a failed validation surfaces its first error with no extra wiring.
{{-- return back()->with('success', 'Saved.');
The viewport reads the session itself — no component on the page. --}}
@foreach (['success' => 'Saved from the session.', 'error' => 'Something went wrong.', 'warning' => 'Storage almost full.', 'info' => 'Heads up.'] as $key => $message)
<hw:form method="post" :action="route('components.toaster.flash')">
<input type="hidden" name="key" value="{{ $key }}">
<input type="hidden" name="message" value="{{ $message }}">
<hw:button type="submit" variant="outline">Flash <code>{{ $key }}</code></hw:button>
</hw:form>
@endforeach
From a Turbo Stream
turbo_stream()->toast() takes the same arguments as the redirect macro, so both branches of a controller read alike. The stream targets the viewport id.
{{-- turbo_stream()->toast(...) targets the viewport id, which defaults to "toaster". --}}
<hw:form method="post" :action="route('toast')">
<input type="hidden" name="type" value="success">
<input type="hidden" name="message" value="Updated successfully.">
<hw:button type="submit" variant="outline">Stream a success</hw:button>
</hw:form>
<hw:form method="post" :action="route('toast')">
<input type="hidden" name="type" value="error">
<input type="hidden" name="message" value="Upload failed.">
<input type="hidden" name="description" value="The server restored the authoritative state.">
<hw:button type="submit" variant="outline">Stream an error</hw:button>
</hw:form>
From JavaScript
The controller publishes the manager as window.toaster on connect — nothing to import. duration: 0 keeps a toast until it is dismissed, and visible-toasts (3 by default) decides how many stay uncollapsed.
{{-- The toaster controller publishes the manager as window.toaster on connect.
Nothing to import: window.toaster.success("Saved") is the whole API. --}}
<hw:button
variant="outline"
data-controller="toaster-demo"
data-toaster-demo-type-value="success"
data-toaster-demo-message-value="Saved"
data-action="toaster-demo#fire"
>
window.toaster.success()
</hw:button>
<hw:button
variant="outline"
data-controller="toaster-demo"
data-toaster-demo-type-value="info"
data-toaster-demo-message-value="Heads up"
data-toaster-demo-position-value="top-end"
data-action="toaster-demo#fire"
>
…with a position override
</hw:button>
{{-- duration="0" keeps a toast up until it is dismissed. --}}
<hw:button
variant="outline"
data-controller="toaster-demo"
data-toaster-demo-type-value="warning"
data-toaster-demo-message-value="Working…"
data-toaster-demo-duration-value="0"
data-action="toaster-demo#fire"
>
…that never auto-dismisses
</hw:button>
{{-- visible-toasts defaults to 3: the rest collapse behind the stack. --}}
<hw:button
variant="outline"
data-controller="toaster-demo"
data-toaster-demo-type-value="success"
data-toaster-demo-message-value="Batch item"
data-toaster-demo-burst-value="5"
data-action="toaster-demo#fire"
>
Fire 5 to see the stack collapse
</hw:button>
Viewport props
ConceptualEvery prop shown at its default. position reads as physical side then logical alignment, so bottom-end follows the document's writing direction.
These configure the viewport in your layout, not individual toasts. A toast can still override
position and duration per call.
<hw:toaster
id="toaster"
position="bottom-center"
:duration="4000"
:visible-toasts="3"
:close-button="true"
:expand="false"
container-aria-label="Notifications"
/>