Sweetalert2 with Laravel 12 and Livewire
Hi all,
I'm using Laravel 12 and Livewire 3, and now i'm trying to use sweetalert2 in may component file.
These are what I already do :
- install sweetalert2 : npm install sweetalert2
- in resources\views\layouts\app.blade.php, after tag : @include('sweetalert::alert')
- in resources\js\app.js : import Swal from "sweetalert2"; window.Swal = Swal;
- in blade file :
@script
@endscript
- in component file when wire:click in the button executed :
$this->dispatch('swal-alert', [
'type' => 'success',
'title' => 'Success!',
'text' => 'Operation completed successfully.'
]);
But sweetalert2 does not show up.
In the blade file, I also using :
Loading...
this button-info is show up, but sweetalert2 does not show up.
Please help..
Thank you...
- in resources\views\layouts\app.blade.php, after body tag : @include('sweetalert::alert')
- in blade file :
@script
tag script
window.addEventListener('swal-alert',function(e){
Swal.fire(e.detail);
});
end tag script
@endscript
In the blade file, I also using :
tag button wire:loading class="btn btn-info"
Loading...
end tag button
Please or to participate in this conversation.