F
Filament11mo ago
ekrbodo

Update related table

I have a custom action which opens a modal, and create records in a related table. I would like to emit a event to update the related table after the record is created. Is there any way to do this? My NoteResource: "->schema([ Actions::make([ Action::make('Send epost') ->disabled(fn(string $operation) :bool => $operation === 'create') ->form([ TextInput::make('type') ->required() ->placeholder(fn ($record) => $record->body) ->maxLength(255), Forms\Components\Textarea::make('content'), Forms\Components\TextInput::make('customer_id') ->default(fn ($record) => $record->customer_id ?? null), Forms\Components\TextInput::make('note_id') ->default(fn ($record) => $record->id ?? null), ]) ->action(function (array $data, string $model): Conversation { Notification::make() ->success() ->title('Epost sendt') ->send(); return Conversation::create($data); }), Action::make('Send sms') ->color('gray') ->action(function () { // do something }), Action::make('Nytt notat') ->color('gray') ->action(function () { // do something }) ]),"
No description
2 Replies
cheesegrits
cheesegrits11mo ago
In your relation manager(s) add a listener like ...
protected $listeners = ['refreshRelations' => '$refresh'];
protected $listeners = ['refreshRelations' => '$refresh'];
... and emit/dispatch it in your action ...
->action(function () {
// do stuff
$this->emit('refreshRelations');
}),
->action(function () {
// do stuff
$this->emit('refreshRelations');
}),
You didn't say if you are using v2 or v3. In v3, it would be $this->dispatch().
ekrbodo
ekrbodo11mo ago
Thanks. I´m using V3. Got it working with this solution: ' #[On('refreshConversation')] public function refresh(): void { }'