From 636d3009a4241ffc85e3904b68b4743dd3655358 Mon Sep 17 00:00:00 2001 From: mohanmd Date: Tue, 7 Jul 2026 17:43:44 +0530 Subject: [PATCH] worker app age field change --- app/Http/Controllers/Admin/WorkerController.php | 16 +++++++++++++++- .../Controllers/Api/WorkerAuthController.php | 16 +++++++++++++++- .../Controllers/Api/WorkerProfileController.php | 16 +++++++++++++++- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Admin/WorkerController.php b/app/Http/Controllers/Admin/WorkerController.php index bcb8a78..313e56c 100644 --- a/app/Http/Controllers/Admin/WorkerController.php +++ b/app/Http/Controllers/Admin/WorkerController.php @@ -133,7 +133,21 @@ public function updateProfile(Request $request, $id) 'salary' => 'nullable|numeric', 'nationality' => 'nullable|string', 'visa_status' => 'nullable|string', - 'age' => 'nullable|integer', + 'age' => [ + 'nullable', + function ($attribute, $value, $fail) { + if (is_numeric($value)) { + $intValue = (int)$value; + if ($intValue < 18 || $intValue > 100) { + $fail('The age must be between 18 and 100.'); + } + } else { + if (!in_array($value, ['18-25', '26-35', '36-45', '46-55', '56-60'])) { + $fail('The age must be a valid number or one of the ranges: 18-25, 26-35, 36-45, 46-55, 56-60.'); + } + } + } + ], 'in_country' => 'nullable', 'preferred_job_type' => 'nullable|string', 'skills' => 'nullable|string', diff --git a/app/Http/Controllers/Api/WorkerAuthController.php b/app/Http/Controllers/Api/WorkerAuthController.php index 069a0a3..f87a54c 100644 --- a/app/Http/Controllers/Api/WorkerAuthController.php +++ b/app/Http/Controllers/Api/WorkerAuthController.php @@ -315,7 +315,21 @@ public function register(Request $request) 'skills' => 'nullable', 'language' => 'nullable|string', 'nationality' => 'nullable|string|max:100', - 'age' => 'nullable|string|in:18-25,26-35,36-45,46-55,56-60', + 'age' => [ + 'nullable', + function ($attribute, $value, $fail) { + if (is_numeric($value)) { + $intValue = (int)$value; + if ($intValue < 18 || $intValue > 100) { + $fail('The age must be between 18 and 100.'); + } + } else { + if (!in_array($value, ['18-25', '26-35', '36-45', '46-55', '56-60'])) { + $fail('The age must be a valid number or one of the ranges: 18-25, 26-35, 36-45, 46-55, 56-60.'); + } + } + } + ], 'experience' => 'nullable|string|max:100', 'in_country' => 'nullable', 'visa_status' => 'nullable|string', diff --git a/app/Http/Controllers/Api/WorkerProfileController.php b/app/Http/Controllers/Api/WorkerProfileController.php index 3927d2f..dbf7e5b 100644 --- a/app/Http/Controllers/Api/WorkerProfileController.php +++ b/app/Http/Controllers/Api/WorkerProfileController.php @@ -70,7 +70,21 @@ public function updateProfile(Request $request) $validator = Validator::make($request->all(), [ 'name' => 'nullable|string|max:255', 'phone' => 'nullable|string|max:50|unique:workers,phone,' . $worker->id, - 'age' => 'nullable|string|in:18-25,26-35,36-45,46-55,56-60', + 'age' => [ + 'nullable', + function ($attribute, $value, $fail) { + if (is_numeric($value)) { + $intValue = (int)$value; + if ($intValue < 18 || $intValue > 100) { + $fail('The age must be between 18 and 100.'); + } + } else { + if (!in_array($value, ['18-25', '26-35', '36-45', '46-55', '56-60'])) { + $fail('The age must be a valid number or one of the ranges: 18-25, 26-35, 36-45, 46-55, 56-60.'); + } + } + } + ], 'nationality' => 'nullable|string|max:100', 'language' => 'nullable|string', 'salary' => 'nullable|numeric|min:0',