sudam-shrestha/sudam-sweet-alert
Composer 安装命令:
composer require sudam-shrestha/sudam-sweet-alert
包简介
This is my package sudam-sweet-alert
README 文档
README
A modern, actively maintained SweetAlert2 wrapper for Laravel 12. Fire beautiful modal alerts and toasts straight from your controllers using session flash data — no manual JS wiring required.
Built as a fresh alternative to older SweetAlert packages that are no longer maintained.
Features
- Simple, chainable API:
success(),error(),warning(),info(),question(),toast() - Built-in toast notifications with sensible defaults (top-right, auto-dismiss)
- Configurable close button, colors, background, and animation on every alert
- Per-call option overrides — any SweetAlert2 option can be passed through
- Zero database/migrations required — pure session flash, works out of the box
Installation
You can install the package via composer:
composer require sudam-shrestha/sudam-sweet-alert
Publish the config file with:
php artisan vendor:publish --tag="sudam-sweet-alert-config"
This is the contents of the published config file:
return [ // Modal alert defaults 'position' => 'center', 'timer' => null, 'show_confirm_button' => true, // Toast defaults 'toast_position' => 'top-end', 'toast_timer' => 3000, // Design — applies to both modals and toasts 'show_close_button' => true, 'confirm_button_color' => '#3085d6', 'cancel_button_color' => '#d33', 'background' => null, 'text_color' => null, 'buttons_styling' => true, 'custom_class' => [], 'cdn' => 'https://cdn.jsdelivr.net/npm/sweetalert2@11', ];
Optionally, publish the views to customize the alert markup:
php artisan vendor:publish --tag="sudam-sweet-alert-views"
Finally, add this once to your main layout, right before </body>:
@include('sudam-sweet-alert::alert')
Usage
Import the facade:
use Sudam\SudamSweetAlert\Facades\SudamSweetAlert;
Modal alerts
SudamSweetAlert::success('Saved!', 'Your changes have been saved.'); SudamSweetAlert::error('Failed', 'Something went wrong.'); SudamSweetAlert::warning('Careful', 'This action cannot be undone.'); SudamSweetAlert::info('Heads up', 'Here is something you should know.'); SudamSweetAlert::question('Are you sure?', 'This will delete the record.'); return redirect()->back();
Toast notifications
SudamSweetAlert::toast('success', 'Saved successfully!');
By default, toasts appear top-right and auto-dismiss after 3 seconds.
Overriding options per call
Any SweetAlert2 option can be passed as the last argument:
SudamSweetAlert::error('Failed', 'Could not save record.', [ 'position' => 'bottom-start', 'timer' => 5000, 'showCloseButton' => false, ]);
Chainable helpers
SudamSweetAlert::success('Saved!') ->timer(4000) ->position('top-end') ->showCloseButton(false);
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-07-13