© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
4 replies
Sesh

How to stop an action on certain conditions with ->before()

What is the best practice in Filament to stop an action from continuing before it runs into a exception? For example I want to show a message to the user if delete is not possible because the category is used for items:

                    DeleteAction::make('delete')
                        ->before(function (TrendRadarTrendSegment $record) {
                            if ($record->radarTrends()->count() > 0) {
                                Notification::make()
                                    ->title('Delete failed')
                                    ->body(__('This segment is used by trends and cannot be deleted. Please move the trends to another segment first.'))
                                    ->danger()
                                    ->send();
                            }
                        })
                    DeleteAction::make('delete')
                        ->before(function (TrendRadarTrendSegment $record) {
                            if ($record->radarTrends()->count() > 0) {
                                Notification::make()
                                    ->title('Delete failed')
                                    ->body(__('This segment is used by trends and cannot be deleted. Please move the trends to another segment first.'))
                                    ->danger()
                                    ->send();
                            }
                        })

How can I break out of the DeleteAction in this case? Or is there another way to catch en exception and show a notification?
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

How to validate repeater items certain conditions before create - Attributes IN repeater items
FilamentFFilament / ❓┊help
2y ago
Modal Slider gets hides modal before requiresConfirmation on Action how top stop that
FilamentFFilament / ❓┊help
6mo ago
Table list edit query based on certain conditions
FilamentFFilament / ❓┊help
2y ago
How to refactor an action?
FilamentFFilament / ❓┊help
3y ago