From 594cc252a99a50a8371734a28070de6f30ecb8b1 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Mon, 15 Sep 2025 12:54:11 +0530 Subject: [PATCH] Added validation error handling in CreateLine page before record creation --- .../LineResource/Pages/CreateLine.php | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/app/Filament/Resources/LineResource/Pages/CreateLine.php b/app/Filament/Resources/LineResource/Pages/CreateLine.php index 864bc38..fe33dbe 100644 --- a/app/Filament/Resources/LineResource/Pages/CreateLine.php +++ b/app/Filament/Resources/LineResource/Pages/CreateLine.php @@ -5,6 +5,7 @@ namespace App\Filament\Resources\LineResource\Pages; use App\Filament\Resources\LineResource; use Filament\Actions; use Filament\Resources\Pages\CreateRecord; +use Illuminate\Validation\ValidationException; class CreateLine extends CreateRecord { @@ -14,4 +15,66 @@ class CreateLine extends CreateRecord { return $this->getResource()::getUrl('create'); } + + protected function beforeCreate(): void + { + $errors = []; + + if (!empty($this->data['lPlantError'])) { + $errors['lPlantError'] = ['Fix the errors before submitting.']; + } + + if (!empty($this->data['lNameError'])) { + $errors['lNameError'] = ['Fix the errors before submitting.']; + } + + if (!empty($this->data['lTypeError'])) { + $errors['lTypeError'] = ['Fix the errors before submitting.']; + } + + if (!empty($this->data['work_group1_id_error'])) { + $errors['work_group1_id_error'] = ['Fix the errors before submitting.']; + } + + if (!empty($this->data['work_group2_id_error'])) { + $errors['work_group2_id_error'] = ['Fix the errors before submitting.']; + } + + if (!empty($this->data['work_group3_id_error'])) { + $errors['work_group1_id_error'] = ['Fix the errors before submitting.']; + } + + if (!empty($this->data['work_group4_id_error'])) { + $errors['work_group4_id_error'] = ['Fix the errors before submitting.']; + } + + if (!empty($this->data['work_group5_id_error'])) { + $errors['work_group5_id_error'] = ['Fix the errors before submitting.']; + } + + if (!empty($this->data['work_group6_id_error'])) { + $errors['work_group6_id_error'] = ['Fix the errors before submitting.']; + } + + if (!empty($this->data['work_group7_id_error'])) { + $errors['work_group7_id_error'] = ['Fix the errors before submitting.']; + } + + if (!empty($this->data['work_group8_id_error'])) { + $errors['work_group8_id_error'] = ['Fix the errors before submitting.']; + } + + if (!empty($this->data['work_group9_id_error'])) { + $errors['work_group9_id_error'] = ['Fix the errors before submitting.']; + } + + //..warranty + if (!empty($this->data['work_group10_id_error'])) { + $errors['work_group10_id_error'] = ['Fix the errors before submitting.']; + } + + if (!empty($errors)) { + throw ValidationException::withMessages($errors); + } + } }