Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working with Laravel Livewire :( #142

Closed
rosolovsky opened this issue Sep 9, 2022 · 7 comments
Closed

Not working with Laravel Livewire :( #142

rosolovsky opened this issue Sep 9, 2022 · 7 comments

Comments

@rosolovsky
Copy link

Not working with Laravel Livewire :(

@realrashid
Copy link
Owner

Please share the installation steps..

@rosolovsky
Copy link
Author

Installation done according to documentation. Package is working in pure Laravel, but not in Livewire components.

@realrashid
Copy link
Owner

Hey @rosolovsky ,

I have tested the package with Livewire it's working as excepted as you can see the image below.

livewire

Please share the error here maybe I will help you.

@dissto
Copy link

dissto commented Sep 15, 2022

Its not working for me either @realrashid

<?php

namespace App\Http\Livewire;

use App\Models\Group;
use Livewire\Component;
use RealRashid\SweetAlert\Facades\Alert;

class CreateGroup extends Component
{
    public $name, $website;

    public function store()
    {
        $validatedData = $this->validate([
            'name'              => ['required', 'string', 'min:3', 'max:255'],
            'website'    => ['required', 'string', 'min:3', 'max:255'],
        ]);

        Group::create($validatedData);

        Alert::toast('Toast Message', 'Toast Type');
        // session()->flash('message', 'Post successfully created.'); this works
    }

    public function render()
    {
        return view('livewire.create-group');
    }
}

The Alerts work fine in any normal controller but seemingly not in a livewire component or class

@dissto
Copy link

dissto commented Sep 15, 2022

It turnes out that you need to have a redirect for it to work.

I had to return a redirect to another page to make them work. If I tried to redirect using the back() method it didn't work either.

@rosolovsky
Copy link
Author

@include('sweetalert::alert')
This directive not load SweetAlert js library in my case. In addition, the sweetAlert2-function "Swal.fire" is not present in the sorce code of the page. This is the reason.

@Sisableng
Copy link

Sisableng commented Jan 9, 2023

@include('sweetalert::alert')

i have same issue, and i trying to add @include('sweetalert::alert') in livewire blade views, its work fine even you set redirect()->back(), just add @include('sweetalert::alert') in your livewire views.

but new problem is when i click again on the button to trigger the alert, it doesn't show anymore unless i refresh the page.
is there any solution for this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants