DEV Community

Süleyman Özgür Özarpacı
Süleyman Özgür Özarpacı

Posted on • Updated on

Refresh Filament Relation Manager After an Action

In my FilamentPHP project, I have an action button that creates relationships for my resource. However, after the relationships are created, the relationship manager needs to be updated. In this article, we will solve this problem.

The Relationship Manager is a Livewire component. By emitting an event to that component, we can refresh it. You can find more information in the Livewire Documentation.

Let's take an example where we create an action that performs certain tasks and then refreshes the relation manager. First, create the action:

Actions\Action::make('example')
    ->action(function ($livewire) {
        // ... Your action code
        $livewire->emit('refreshExampleRelationManager');
    }),
Enter fullscreen mode Exit fullscreen mode

Next, listen to this event in your relation manager:


class ExampleRelationManager extends RelationManager
{
    ...
    protected $listeners = ['refreshExampleRelationManager' => '$refresh'];
    ...
}
Enter fullscreen mode Exit fullscreen mode

By following these steps, you can ensure that the relationship manager gets updated after the creation of relationships.

Edit: emit method changed to dispatch in Livewire v3.

Top comments (0)