ali-habibian / sweetalert2-laravel
This package provides an easy-to-use integration for SweetAlert2 notifications in Laravel applications.
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:package
Requires
- illuminate/support: ^11.34
This package is auto-updated.
Last update: 2025-05-29 01:58:28 UTC
README
Installation
-
Install the package: In your Laravel app, run:
composer require ali-habibian/sweetalert2-laravel
-
Publish assets: Publish the package’s JavaScript file to your public directory:
php artisan vendor:publish --tag=assets
-
Install SweetAlert2 via npm: In your Laravel app's root directory, run:
npm install sweetalert2
-
Compile your assets: After installing SweetAlert2, run the following command to compile your JavaScript assets:
npm run dev
Or for production:
npm run prod
-
Include the compiled JavaScript: In your
resources/views/layouts/app.blade.php
or wherever you include your main JavaScript, add the following line to load the compiled file:<script src="{{ asset('js/vendor/swalalert.js') }}"></script>
-
Usage: In your controller, you can now easily flash an alert:
use AliHabibian\Sweetalert2Laravel\SwalLaAlert; public function store() { SwalLaAlert::flash('success', 'Product added successfully!'); return redirect()->route('home'); }
Customization
You can customize the default confirmation button text by editing the configuration file located at config/swalalert.php
.
For example, to change the default confirmation button text:
return [ 'confirm_button_text' => 'Confirm', ];