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

juanborras's avatar

Livewire dispatch()->to()

Hey there!

I'm developing a web page in livewire. There is a Livewire BookComponent with a button "Add new page" that calls a method in the controller that redirects to another Livewire controller, PageController that displays a form. When the save button is pressed a "save" methos inside PageController is called, and at the end of the method I want to notify the BookController that the page has been saved, so I do

$this->dispatch('page-saved')->to(BookController::class);

Inside the BookController there is this method

#[On('page-saved')
public function newPageSaved() {
  dd('Page saved event received');
}

But, the newPageSaved() never gets called... What am I missing? any ideas?

Thanks!!

0 likes
2 replies
bcalbatros's avatar

same problem, and found the reason. To register listeners, the page has #[On()] method must be visited. Then it is starting to listen events. BaseOn class store the listeners to activate them. I guess, I will move my listeners index page :/

vendor/livewire/livewire/src/Features/SupportEvents/BaseOn.php

Please or to participate in this conversation.