Β© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filamentβ€’3y agoβ€’
4 replies
at92

Unable to dispatch/listen event from Action

I'm unable to dispatch and/or listen to a Livewire event from an Action. I have a resource with a table and a custom action that looks like this:

Action::make('switchTeam')
            ->label(__('Switch team'))
            ->icon('heroicon-s-arrow-right-circle')
            ->color('gray')
            ->action(function (Team $team) {
                // Something happens here
            })
            ->dispatch( 'switchedTeam' )
Action::make('switchTeam')
            ->label(__('Switch team'))
            ->icon('heroicon-s-arrow-right-circle')
            ->color('gray')
            ->action(function (Team $team) {
                // Something happens here
            })
            ->dispatch( 'switchedTeam' )


I then have a custom livewire component that I've loaded through render hooks inside the header bar next to the user's menu. In the component I've tried the following methods but nothing is being fired.

1st test:
protected $listeners = [
  'switchedTeam' => 'fireEvent',
];
protected $listeners = [
  'switchedTeam' => 'fireEvent',
];


2nd test:

#[On('switchedTeam')]
public function fireEvent() {
  Log::info('fireEvent');
}
#[On('switchedTeam')]
public function fireEvent() {
  Log::info('fireEvent');
}


But nothing is happening. What am I doing wrong? Thanks πŸ™
Solution
try this:
->action(function (Team $team) {
    //action here
})
->after(fn ($livewire) => $livewire->dispatch('switchedTeam'))
->action(function (Team $team) {
    //action here
})
->after(fn ($livewire) => $livewire->dispatch('switchedTeam'))


your component
use Livewire\Attributes\On;

#[On('switchedTeam')]
public function fireEvent()
{
    Log::info('fireEvent');
}
use Livewire\Attributes\On;

#[On('switchedTeam')]
public function fireEvent()
{
    Log::info('fireEvent');
}
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel β€’ Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

How to dispatch an event from an Action
FilamentFFilament / β“β”Šhelp
16mo ago
How to dispatch an event from a Notification Action
FilamentFFilament / β“β”Šhelp
3y ago
dispatch livewire event after action execution
FilamentFFilament / β“β”Šhelp
2y ago
Dispatch event not working on action
FilamentFFilament / β“β”Šhelp
3y ago