Where would you put action logic that handles validation?

Refactoring some duplicate code and wondering where you recommend putting validation logic for deletes on both DeleteAction and DeleteBulkAction.

E.g
Tables\Actions\DeleteBulkAction::make()
    ->before(function (Tables\Actions\DeleteBulkAction $action) {
        foreach ($action->getRecords() as $record) {

            if ($record->staff()->exists()) {
                Notification::make('not_deletable')
                    ->warning()
                    ->title('This record can not be deleted because it is in use')
                    ->body(__('Reason why'))
                    ->persistent()
                    ->actions([
                        Action::make('staff')
                            ->button()
                            ->url(StaffResource::getUrl(
                                'index',
                                ['tableFilters[project_id][value]' => $record->id]
                            )),
                    ])
                    ->send();

                $action->cancel();

            }



Filament\Actions\DeleteAction::make()
    ->before(function (Filament\Actions\DeleteAction $action) {
        $record = $action->getRecord();

        if ($record->staff()->exists()) {
            Notification::make('not_deletable')
                ->warning()
                ->title('This record can not be deleted because it is in use')
                ->body(__('Reason why'))
                ->persistent()
                ->actions([
                    Action::make('staff')
                        ->button()
                        ->url(StaffResource::getUrl(
                            'index',
                            ['tableFilters[project_id][value]' => $record->id]
                        )),
                ])
                ->send();

            $action->cancel();

        }
Was this page helpful?