DEV Community

Discussion on: Global livewire notifications with SweetAlert

Collapse
 
bayu profile image
Diarsa

if my namespace is namespace App\Http\Livewire\Admin\Main; and the class is Org, and method I want to call is delete, then what should I fill in the 'method' ?

Thread Thread
 
ph7jack profile image
Pedro Henrique

you put the name of the listener, no matter where the class is, what is taken into account is the name of the listener.
An important point to think about is that there can be 2 components with the "delete" listener, so put a prefix in this case, ex: "user: delete" and "team: delete"

Thread Thread
 
bayu profile image
Diarsa

I try to protected $listeners = ['confirm' => 'syncFromDC']; but nothing happen after click Oke.

Thread Thread
 
bayu profile image
Diarsa
Thread Thread
 
8rux40 profile image
Bruno Tardin • Edited

Any solution? Same thing here... After confirm the dialog nothing happens.
This is some of my User class:

public function confirmDelete($id){
        $this->emit("swal:confirm", [
            'type'        => 'warning',
            'title'       => 'Tem certeza?',
            'text'        => "Você não poderá reverter isso!",
            'confirmText' => 'Sim, desativar!',
            'method'      => 'usuario:delete',
            'params'      => $id, // optional, send params to success confirmation
            'callback'    => '', // optional, fire event if no confirmed
        ]);
    }

public function delete($id) {
        if ($id){
            User::find($id)->delete();
            $this->emit('swal:alert', [
                'type'  => 'success',
                'title'  => "Usuário desativado com sucesso!",
                'timeout' => 3000,
            ]);
        }
    }
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
8rux40 profile image
Bruno Tardin

Works for me now that I have declared the $listeners in my Usuario class:

protected $listeners = ['usuario:delete' => 'delete'];
...
public function confirmDelete($id){
        ...
    }

public function delete($id) {
        ...
    }
Enter fullscreen mode Exit fullscreen mode