Usually, in Filament, you have a relation manager below Edit forms. What if you want to refresh the relation manager data from the database? In this quick tutorial, let's see how to do that.
A more typical use-case is to refresh the main form after relation manager has changed. For that, we have a tutorial and an example. What about the other way around, if you want to refresh the relation manager itself?
To do this, we need to dispatch an event after the action button is pressed in the relation manager and listen for it in the same relation manager class. We. can do this because the relation manager is a Livewire component.
On the action, the dispatchSelf()
method can be used to dispatch an event on the same component by providing the event name.
use Filament\Tables;use Filament\Tables\Table; public function table(Table $table): Table{ return $table // ... ->headerActions([ Tables\Actions\Action::make('refresh') ->outlined() ->dispatchSelf('refreshComments'), ]) // ...}
Then, in the same relation manager class, you should listen to the event on the refresh()
method.
use Livewire\Attributes\On; #[On('refreshComments')]public function refresh(): void{}
A few of our Premium Examples: