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 Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

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

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay