Global listeners for form events create/edit/deleted?

Is there a way of listening for all changes in Filament? E.g to save doing this on every action
Tables\Actions\EditAction::make()
->after(function ($livewire, $record) {
if ($record->wasChanged()) {
$livewire->emit('dataChanged');
}
}),
Tables\Actions\EditAction::make()
->after(function ($livewire, $record) {
if ($record->wasChanged()) {
$livewire->emit('dataChanged');
}
}),
4 Replies
LeandroFerreira
Is it a --simple resource?
gizmojo
gizmojoOP2y ago
Both types wanting it to work globally across all resources
LeandroFerreira
I'm not sure, but you can try to use ->configureUsing() inside a service provider
gizmojo
gizmojoOP2y ago
Thanks I'll give that a try. Wow surprised just how well this worked for most actions. I'm finding not all actions call the after event. So far found issues with: 1. Standard resource after event is never called for CreateAction and DeleteBulkAction 2. Simple resource CreateAction after event is only called when you click 'Create & create another'.
Filament::serving(function() {
Tables\Actions\Action::configureUsing(function (Tables\Actions\Action $action) {
$action->after(function($record, $livewire) use($action) {
if ($action instanceof Tables\Actions\EditAction) {
$changed = $record->wasChanged();
} else {
$changed = true;
}
if ($changed) {
$livewire->emit('dataChanged');
}
});
});

Pages\Actions\Action::configureUsing(function (Pages\Actions\Action $action) {
$action->after(function($record, $livewire) use($action) {
if ($action instanceof Pages\Actions\EditAction) {
$changed = $record->wasChanged();
} else {
$changed = true;
}
if ($changed) {
$livewire->emit('dataChanged');
}
});
});
});
Filament::serving(function() {
Tables\Actions\Action::configureUsing(function (Tables\Actions\Action $action) {
$action->after(function($record, $livewire) use($action) {
if ($action instanceof Tables\Actions\EditAction) {
$changed = $record->wasChanged();
} else {
$changed = true;
}
if ($changed) {
$livewire->emit('dataChanged');
}
});
});

Pages\Actions\Action::configureUsing(function (Pages\Actions\Action $action) {
$action->after(function($record, $livewire) use($action) {
if ($action instanceof Pages\Actions\EditAction) {
$changed = $record->wasChanged();
} else {
$changed = true;
}
if ($changed) {
$livewire->emit('dataChanged');
}
});
});
});
Want results from more Discord servers?
Add your server