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

myregistration's avatar

Does anyone know how to listen for Livewire events in a Filament Resource?

When using a Filament Resource that includes a form and table, I dispatch an event from the afterSave() method in it's relative EditRecord page and I have the listener set up in the Resource page. I added some JS to test the listener and I get an alert, so looks like the dispatch is working, but the listener method in Resource isn't getting called.

In Resource: ( I tried with both styles of Livewire listeners)

	protected $listeners = ['records-updated' => 'refreshRecords'];   // alternative: '$refresh'

    #[On('records-updated')]
    public function refreshRecords(): void
    {
        dd('refreshRecords');
    }

In EditRecord:

    public function afterSave(): void
    {
		// dd('afterSave');   // I tested and it gets here

        // This should trigger event to refresh records
        $this->dispatch('records-updated');
    }
0 likes
1 reply
myregistration's avatar
myregistration
OP
Best Answer
Level 14

I solved it by putting the listeners in the ListRecord, EditRecord, and CreateRecord pages, not the relative Resource page. To refresh the edit form after updating, for example, you would use refreshFormData() and pass it the field names you want to refresh. For example, $this->refreshFormData(['created_at', 'updated_at']);. Normally you probably wouldn't need to do this, but I did because I auto-set some date fields based on the $status that was submitted.

Here's an updated example:

class EditUser extends EditRecord
{
    protected static string $resource = UserResource::class;

	#[On('user-updated')]
    public function userFormUpdated(): void
    {
        $this->refreshFormData(['terminated_at', 'joined_at', 'approved_at']);
    }

    public function afterSave(): void
    {
        // Run update of status to make sure dates are proper
        $this->record->processUser(status: $this->record->status);

        // This should trigger event to refresh user form
        $this->dispatch('user-updated');
    }
}

Also, using an event listeners array didn't appear to work, so use the #[On('eventName')] format. Don't forget to import the On class!

Didn't work:

protected $listeners = ['user-updated' => 'userFormUpdated'];

Did work:

#[On('user-updated')]
public function userFormUpdated(): void
{
1 like

Please or to participate in this conversation.