Installation
Requires PHP 8.1+, Laravel 10+, Livewire 3.x or 4.x, and SweetAlert2.
Install the package
Pull it in via Composer.
Shell
LivewireAlert
composer require jantinnerezo/livewire-alert
Publish the config (optional)
Only needed if you want to override defaults like position or button text.
Shell
LivewireAlert
php artisan vendor:publish --tag=livewire-alert:config
Install SweetAlert2 via npm
Recommended for Vite-based projects.
Shell
LivewireAlert
npm install sweetalert2
Then import it in resources/js/app.js:
JavaScript
LivewireAlert
import Swal from 'sweetalert2'
window.Swal = Swal
Or via CDN
Drop a script tag into your Blade layout if you prefer not to bundle it.
HTML
LivewireAlert
<body>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
</body>
Filament
Register SweetAlert2 as a Filament asset in your AppServiceProvider boot method.
PHP
LivewireAlert
use Filament\Support\Facades\FilamentAsset;
use Illuminate\Support\Facades\Vite;
use Filament\Support\Assets\Js;
public function boot()
{
FilamentAsset::register([
Js::make('sweetalert2', Vite::asset('resources/js/sweetalert2.js')),
// Or via CDN:
// Js::make('sweetalert2', 'https://cdn.jsdelivr.net/npm/sweetalert2@11'),
]);
}
Next: Basic usage →