<x-widget.alert>
Alert Blade component for Laravel and Livewire
Messages that stay on the page, in info, success, warning and error, with a title, actions and an optional dismiss button. flash="status" shows the session message Laravel's auth screens set. Includes an error summary for the top of a form that links each validation error to its field. Works inside Livewire components.
php artisan bladewell:add alert
- Also adds
- Icon
- Works with
- Laravel 12 and 13, Livewire 3 and 4, Tailwind CSS 4.1+, PHP 8.3+
Usage
From a controller
flash="status" reads the key Laravel's password reset and email verification screens already use.
return back()->with('status', 'We have emailed your password reset link.');
// Some starter kits flash a code instead of a sentence. Put the words in the view:
// @if (session('status') === 'verification-link-sent')
// <x-widget.alert tone="success">A new verification link is on its way.</x-widget.alert>
// @endif
// For 'success', 'error', 'warning' and 'info', use <x-widget.toast>; the alert leaves those keys alone.
return back()->with('success', 'Profile updated.');
Livewire
Inside a Livewire component: a render updates an alert's text and tone in place. A dismissed one stays hidden through later renders while it says the same thing, and shows again when its message changes. flash="status" picks up session()->flash('status', …) from an action and reads it out like after a redirect. After a failed wire:submit the error summary gets focus, as after an ordinary form, though never while someone is typing, so validateOnly() in updated() can't pull them out of a field.
<form wire:submit="save" class="space-y-5">
<x-widget.alert flash="status" tone="success" />
<x-widget.alert.errors />
<x-widget.text-input label="Name" wire:model="name" />
<x-widget.text-input label="Email" type="email" wire:model="email" />
<button type="submit">Save</button>
</form>
Examples
Tones
Four tones, each with its own icon, so colour is never the only signal. The title is optional.
Payment received
Your trial ends in 3 days
Payout failed
Show code Hide code
<div class="grid max-w-2xl gap-3">
<x-widget.alert>Exports run overnight and are ready by 6am.</x-widget.alert>
<x-widget.alert tone="success" title="Payment received">We've emailed a receipt to [email protected].</x-widget.alert>
<x-widget.alert tone="warning" title="Your trial ends in 3 days">Add a card to keep your projects running.</x-widget.alert>
<x-widget.alert tone="error" title="Payout failed">The bank rejected the transfer. Check the account details and try again.</x-widget.alert>
</div>
With actions
The actions slot holds links or buttons that act on the message.
Your trial ends in 3 days
Show code Hide code
<x-widget.alert tone="warning" title="Your trial ends in 3 days" class="max-w-2xl">
Add a card to keep your projects running after 30 September.
<x-slot:actions>
<a href="#billing" class="text-foreground underline underline-offset-4">Add a card</a>
<a href="#plans" class="text-foreground/70 hover:text-foreground">Compare plans</a>
</x-slot:actions>
</x-widget.alert>
Dismissible
dismissible adds a close button. It hides the alert for this page view; to keep it hidden, remember the choice on the server.
Show code Hide code
<x-widget.alert dismissible class="max-w-2xl">Exports have moved to the Reports page.</x-widget.alert>
Flash status
flash="status" shows session('status') when there is one and nothing otherwise, so it can live in your layout. Laravel's auth screens flash under status; see Usage. It's announced to screen readers, as a message after an action should be.
Show code Hide code
<x-widget.alert flash="status" tone="success" dismissible class="max-w-2xl" />
Error summary
Put it at the top of a form. It lists each field's first error, and each links to its field. After a failed submit it takes focus, so screen readers read the problems out. For a named error bag, pass bag="…".
Show code Hide code
<x-widget.alert.errors class="max-w-2xl" />
Props
Other attributes, such as autocomplete or data-*, are passed through to the element. class styles the component's outer wrapper.
<x-widget.alert>
| Prop | Default | Description |
|---|---|---|
| tone |
'info'
|
info, success, warning or error: sets the colours and the icon. |
| title |
null
|
A bold first line above the message. |
| flash |
null
|
A session key, e.g. "status": shows what was flashed under it, and nothing at all when nothing was. Read out to screen readers when it appears (error and warning interrupt). |
| icon |
null
|
An icon name in place of the tone's own; false for none. |
| dismissible |
false
|
A close button that hides it for this page view; remember the choice on the server to keep it hidden. |
| dismiss-label |
null
|
The close button's name for screen readers. Defaults to "Dismiss". |
<x-widget.alert.errors>
| Prop | Default | Description |
|---|---|---|
| title |
null
|
The heading. Defaults to "There is a problem" or "There are 3 problems". |
| bag |
'default'
|
Which error bag to read the errors from. |
Accessibility
All 5 examples above are 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 alert 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/alert/errors.blade.php Show
resources/views/components/widget/alert/index.blade.php Show
resources/js/widget/alert/index.js Show
app/View/Widget/ElementIds.php Show
app/View/Widget/FormField.php Show