Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Livewire Alert

Livewire Alert Laravel Package

jantinnerezo/livewire-alert

Livewire Alert integrates SweetAlert2 with Laravel Livewire so you can fire toasts, confirmation dialogs, and flash messages straight from your components using a simple fluent API. It handles the JavaScript wiring, keeping all your alert logic in PHP—no front-end code required.

View on GitHub
Deep Wiki
Context7

SweetAlert2 integration for Livewire

Frequently asked questions about Livewire Alert
How do I install and set up jantinnerezo/livewire-alert in a Laravel application?
Install it with Composer using composer require jantinnerezo/livewire-alert, then add the package's LivewireAlert trait to any Livewire component that needs to fire alerts. The package takes care of the JavaScript wiring so you only call its fluent PHP API from your component methods. SweetAlert2 itself remains the single front-end prerequisite, and the v4.2.0 release notes imply no new service provider, config file, or asset pipeline changes. A single developer can typically wire it into a staging component in an afternoon.
Which Laravel and Livewire versions does livewire-alert support?
The package is a thin wrapper over SweetAlert2 that exposes a fluent PHP API to Livewire components, so its compatibility is driven by the Livewire and PHP constraints declared in its composer.json. Check those constraints before adding it to an existing project, especially if you are still on Livewire 2 or an older Laravel release. v4.2.0 is described as an additive release that introduces a server-driven alert lifecycle, so confirm your installed Livewire version supports the event-based approach it uses. Pinning a known-good version and testing on staging is the safest path.
How do I show a toast notification or flash message from a Livewire component?
Use the LivewireAlert trait in your component and call the alert helper from a component method, passing an alert type such as success, error, or warning along with your title and optional SweetAlert2 options. Because the call happens in PHP, you never write Swal.fire() yourself and your notification logic stays next to the business logic that triggered it. The flash variant survives a redirect, which makes it a good fit for post-save or post-delete messages. Positioning, timers, and toast styling are passed through the options payload to SweetAlert2.
How do I add a SweetAlert2 confirmation dialog before a destructive action?
Fire a confirmation alert from the component method and route the user's choice back into Livewire through the confirm and dismiss callbacks, so the actual delete or update still runs server-side. This keeps the confirmation flow in PHP rather than scattering JavaScript across Blade templates. For very simple cases Livewire's built-in wire:confirm attribute can be enough, but livewire-alert is the better fit when you want styled dialogs, custom button text, or the same API used for your toasts. Remember that the dialog itself is not a security boundary, so authorization must still be enforced in the component.
How do I show a loading modal and update it while a queued job or batch runs?
Call asLoading() to open a preset alert that disables dismissal, blocks backdrop clicks, and invokes Swal.showLoading() so users cannot click away from a modal they should not close. From there, pair wire:poll with update() to mutate the open alert in place as your Bus::batch or job progresses. Be aware that every poll tick issues both a Livewire request and a DOM mutation, so several such components on one dashboard can amplify server load. Also plan for the case where the alert is not actually open, because update() then becomes a silent no-op.
What is the difference between the fluent update() and passing an explicit options array?
The fluent form only emits the options you explicitly set, while the explicit form sends exactly the payload you hand it. Neither merges your config defaults into the call, which is deliberate: merging defaults into an update would overwrite the existing state of the live alert. The trade-off is a dual mental model that every developer on the project must internalize, and it is the most likely source of integration bugs. Pick one convention per codebase and document it.
Why does close() or update() do nothing and only log a console warning?
Both methods no-op with a console warning when no alert is currently visible on the page. That is a reasonable UX safeguard, but console warnings are invisible in production and server-side code that succeeds with no visible effect is hard to debug. The deeper issue is that alert identity is implicit: the PHP side holds no handle or ID for the alert open in the browser, so a Livewire re-render, navigation, or concurrent alert breaks the pairing. Add your own server-side logging or state flag around alert emission if the visible outcome matters.
Will upgrading to v4.2.0 break my try/catch blocks around alert calls?
The release notes state that guards run before the call and no longer throw, which is additive at the type level but not necessarily safe for consumer logic. Any code that relied on a thrown exception as a control-flow signal, such as a try/catch around alert emission or a queue failure handler, will silently change behavior after the upgrade. Audit those call sites and test them before rolling out. Treat this as a behavioral change to confirm rather than a purely non-breaking addition.
Are alert titles, text, and options escaped before reaching SweetAlert2?
The v4.2.0 release notes do not describe an escaping posture, so assume values flow through to SweetAlert2 as given. SweetAlert2 renders HTML when the html option is enabled, which means user-influenced strings such as names or raw error messages could become an injection vector. Escape or sanitize on the server before passing anything user-controlled, and avoid enabling html for dynamic content. Confirm the behavior against the source before shipping this into any tenant-facing surface.
Can I test livewire-alert alerts with PHPUnit or Pest?
Yes, but test the PHP contract rather than the rendered SweetAlert2 DOM. The package communicates from the component to the browser through dispatched events, so assert the event and its payload with Livewire's testing helpers such as assertDispatched or assertDispatchedBrowserEvent inside Livewire::test(). That lets you verify that a save, delete, or confirmation callback triggers the right alert without booting a browser. Keep separate Dusk or browser tests only if you genuinely need to verify SweetAlert2 rendering.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core
nodisrupt/laravel-agent