realrashid/sweet-alert
Laravel wrapper for SweetAlert2 that makes it easy to show stylish alert, toast, and confirmation dialogs. Flash messages from controllers or middleware, with helpers for success/error/warning/info, custom options, and Blade support for quick integration.
Pros:
Alert::success(), toast(), confirmDelete()) align with Laravel’s controller/service layer patterns.Cons:
HandleIncomingRequests) may conflict with existing error pages if not configured carefully.@{{ }} for nested Blade).Alert facade conflicts with existing code, use app('alert') or alias in config/app.php.| Risk Area | Mitigation Strategy |
|---|---|
| Laravel version skew | Pin to ^7.3 for stability; monitor Laravel 14 compatibility. |
| JS asset conflicts | Use CDN or publish assets to public/vendor; exclude from Vite preloading. |
| Middleware clashes | Test with php artisan route:list to validate error handling routes. |
| IDE support | @method PHPDoc annotations (v7.3.2+) reduce refactoring risk. |
| Performance | Bundle JS only on demand (config: load_js_always = false). |
@alert directives.window.SweetAlert globally or pass props from Laravel.route('alert.store')).cdn_url = 'https://cdn.jsdelivr.net/npm/sweetalert2@11').php artisan vendor:publish --tag=sweet-alert-assets.Alert::success() in a controller).@alert('Operation completed!')).Alert::error().deprecated() in custom helpers.SweetAlert JS if needed).session()->flash() for async jobs.return response()->json(['alert' => 'Success'])).wire:ignore on SweetAlert elements to avoid reactivity conflicts.@layer in global CSS.composer require realrashid/sweet-alert
php artisan vendor:publish --tag=sweet-alert-config
php artisan vendor:publish --tag=sweet-alert-assets
load_js_always = false in config/sweet-alert.php for lazy loading.Alert::warning()->title('Test')).config/sweet-alert.php.@{{ }} for dynamic content containing {}.cdn_url per environment.POST /api/alerts) or shared config.| Scenario | Impact | Mitigation |
|---|---|---|
| JS Bundle Fails | Alerts render as plain text. | Fallback to Bootstrap modals. |
| Facade Not Bound | Alert::success() throws error. |
Verify SweetAlertServiceProvider. |
| Blade Compilation | Directives fail in dynamic views. | Escape with @{{ }}. |
| SweetAlert2 JS Bug | UI glitches (e.g., stuck loader). | Downgrade to last stable version. |
| Session Timeout | Flash messages lost. | Use session()->putNow() for critical alerts. |
How can I help you explore Laravel packages today?