Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sultanzaki's avatar

Dispatch() not working on Livewire 3

I have a problem where the dispatch didn't do anything. I'm using Livewire v3.5.2. So I have a form for updating the data in my database. The Livewire component to handle the form look like this,

public function updateValas() { $this->validate();

    try {
        Valas::find($this->editingId)->update($this->editingValas);
        $this->closeEditModal();
        session()->flash('message', 'Data Valas berhasil diperbarui.');
        $this->dispatch('refreshValas');  // Menggunakan dispatch untuk update edit
    } catch (\Exception $e) {
        session()->flash('error', 'Terjadi kesalahan saat memperbarui data.');
    }
}

Then, the listeners is from the main component, it look like this, protected $listeners = [ 'refreshCounterRates' => 'refreshCounterRates', 'refreshVideo' => 'refreshVideo', 'refreshImage' => 'refreshImage', 'refreshValas' => 'refreshValas', ];

public function refreshValas()
{
    \Log::info('refreshValas event received');
    $valas = Valas::all()->toArray();
    $totalValas = count($valas);
    $halfCount = ceil($totalValas / 2);

    $this->valasTable1 = array_slice($valas, 0, $halfCount);
    $this->valasTable2 = array_slice($valas, $halfCount);
}

public function mount($playlistId)
{
    $this->playlistId = $playlistId;
    $this->refreshQueue();
    $this->refreshValas();
    $this->refreshCounterRates();
    $this->refreshVideo();
    $this->updateDateTime();
    $this->updateLastUpdateTime();
    $this->refreshImage();
}

But nothing happen. I already do logging, the event successfully dispatched but nothing received. I try to use instruction from documentation like this,

#[On('refresh-valas')] public function refreshValas() { \Log::info('refreshValas event received'); $valas = Valas::all()->toArray(); $totalValas = count($valas); $halfCount = ceil($totalValas / 2);

    $this->valasTable1 = array_slice($valas, 0, $halfCount);
    $this->valasTable2 = array_slice($valas, $halfCount);
}

But, the result is the same. Its not changing. Anyone can help this?

I hope I find the problem to see what's wrong

0 likes
0 replies

Please or to participate in this conversation.