diff --git a/app/Filament/Admin/Resources/BenefitResource/Pages/CreateBenefit.php b/app/Filament/Admin/Resources/BenefitResource/Pages/CreateBenefit.php index e28c6563..ee0e2a84 100644 --- a/app/Filament/Admin/Resources/BenefitResource/Pages/CreateBenefit.php +++ b/app/Filament/Admin/Resources/BenefitResource/Pages/CreateBenefit.php @@ -45,4 +45,15 @@ protected function getHeaderActions(): array ->url(BenefitResource::getUrl()), ]; } + + public function mutateFormDataBeforeCreate(array $data): array + { + foreach ($this->data['benefitTypes'] as $key => $value) { + if (! $value['name']) { + unset($this->data['benefitTypes'][$key]); + } + } + + return $data; + } } diff --git a/app/Filament/Admin/Resources/BenefitResource/Pages/EditBenefit.php b/app/Filament/Admin/Resources/BenefitResource/Pages/EditBenefit.php index 93ac601d..5e703812 100644 --- a/app/Filament/Admin/Resources/BenefitResource/Pages/EditBenefit.php +++ b/app/Filament/Admin/Resources/BenefitResource/Pages/EditBenefit.php @@ -51,4 +51,13 @@ protected function getHeaderActions(): array ->tooltip(fn (Actions\DeleteAction $action) => $action->isDisabled() ? __('nomenclature.helper_texts.delete_benefit') : ''), ]; } + + public function beforeSave(): void + { + foreach ($this->data['benefitTypes'] as $key => $value) { + if (! $value['name']) { + unset($this->data['benefitTypes'][$key]); + } + } + } }