Swal is not defined using laravel livewire component

322 Views Asked by At

I am using laravel livewire component and I want to provide feedback to users with sweetalerts (realrashid/sweet-alert) using Swal.

I am getting this issue in console: Swal is not defined

This is my component class:

 $this->dispatchBrowserEvent('swal', [
            'title' => __('Meal created successfully.'),
            'timer'=> 3000,
            'icon'=> 'success',
            'toast'=> true,
            'position'=> 'top-right'
        ]);

and this is its view:

@push('scripts')
    <script>
        window.addEventListener('swal', function (e) {
            Swal.fire(e.detail)
        });
    </script>
@endpush

This is main blade where I have stack of scripts:

<livewire:scripts/>
@include('sweetalert::alert')
@stack('scripts')

I guess the order is right...

Also, I have followed realrashid docs for installation of the sweetalerts and I have installed sweetalert2 with npm.

I have done this before but I am missing something now.

Thanks in advance!

0

There are 0 best solutions below