realrashid/sweet-alert
Laravel package that brings SweetAlert2 to your app with a fluent PHP API. Flash success, error, and toast alerts, or build confirm dialogs right from your controllers—no JavaScript boilerplate needed.
data-confirm-delete / data-confirm attributes let you guard any link or form declaratively, with per-element copy overrides (data-confirm-title, -text, -icon, -button, -cancel). No bespoke JS per screen, which means PMs can spec confirm copy as content, not as an engineering ticket.confirmDelete() had been flashed; on any other render the link was plain HTML and the browser issued a GET to the destroy URL. v8's listener is always present, and if the SweetAlert2 CDN is unreachable it falls back to the browser's native confirm(). That's a "destructive action can never fire unasked" guarantee — worth prioritizing on its own, and a good line item for a security review.Alert::input(...)->submitTo(route(...), 'POST', 'field') collects a single value (a name, a reason for cancellation, a refund note) and posts it to your server. This is a cheap way to ship "capture a reason" features that would otherwise need a form page and a route and a validation request.topLayer() puts popups in the browser's top layer above any z-index, which closes the perennial "toast renders behind the navbar" bug. Treat this as a design-system constraint you can specify once rather than a per-page fix.alert:upgrade codemod. If your roadmap includes a Laravel upgrade, the package's release cadence tells you it will follow you; that is a real (if modest) input to sequencing.Adopt when:
Alert::success() in 52 files. If usage is broad, the abstraction pays for itself; if it's two dialogs, it doesn't.vendor/, with optional CDN. That's a plus for teams without a front-end pipeline, and a downside for teams with a strict CSP or a bundle-size budget.Look elsewhere when:
submitTo() handles one field, not a form.background, width and padding as inline styles that beat every stylesheet — this is why v8 defaults them to null. Theming and CSP can fight each other here.Alerts helper, and budget a day per Laravel major for upgrades.For executives (one paragraph): This is a free, MIT-licensed Laravel package that gives our app professional, accessibility-compliant popups — confirmations, success/error messages, toasts, and simple input prompts — without us building or maintaining any front-end dialog code. The concrete win is around destructive actions: deleting a record, refunding an order, closing an account. Today those confirmations are bespoke per screen, and the v7 version of this package had a real defect where a "guarded" delete could execute without being confirmed. The current version guarantees a confirmation is always shown, and falls back to the browser's own prompt if the CDN is unavailable. Cost is effectively zero; the risk is that it's a small open-source project with one primary maintainer, which we manage by pinning versions and wrapping our usage behind a thin internal helper so we could swap it out in a day.
For engineering (the short version): It's a Laravel-native builder over SweetAlert2 — AlertBuilder, ToastBuilder, InputBuilder, PHP 8.3 enums (AlertType, InputType, Position), when()/unless()/macro() on every builder, a @sweetAlert Blade directive replacing @include('sweetalert::alert'), and Livewire v4 / Inertia middleware support. Declarative guards for forms and links (data-confirm, data-confirm-delete, data-confirm-method) build a CSRF-correct form and submit it for you, so no per-screen JavaScript. It ships Pest tests, PHPStan level 5, Pint, and a tokenizer-based php artisan alert:upgrade --dry-run codemod that rewrites the two changed signatures and the config keys — validated against five real applications, 1,065 files scanned, 16 rewritten, no false positives. Watch out: v7's html($title, $code, $icon) became html($html) in v8, and PHP silently ignores the surplus arguments, so an un-migrated call doesn't error — it just stops working. Run the upgrade command. Requirements: PHP 8.3+, Laravel 11/12/13.
What I'd ask for: Approve adoption for the confirmation/toast use case only, pin to the current minor, and require that all usage go through a single internal Alerts wrapper so we retain the option to replace it. Revisit if the maintainer goes quiet for two consecutive Laravel majors.
How can I help you explore Laravel packages today?