DEV Community

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

Posted on • Edited on

7

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.

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs