From d235b958758791e7a752b59d5def0748ff00ffe7 Mon Sep 17 00:00:00 2001 From: wahyun Date: Wed, 15 May 2024 12:08:38 +0700 Subject: [PATCH] fix: validation add & update --- app/Http/Controllers/HumanResourceController.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/HumanResourceController.php b/app/Http/Controllers/HumanResourceController.php index 1cbee8b..14c44fa 100644 --- a/app/Http/Controllers/HumanResourceController.php +++ b/app/Http/Controllers/HumanResourceController.php @@ -3,7 +3,6 @@ namespace App\Http\Controllers; use App\Models\User; -use Illuminate\Support\Str; use App\Models\UserToProyek; use Illuminate\Http\Request; use App\Models\HumanResource; @@ -18,15 +17,15 @@ class HumanResourceController extends Controller public function add(Request $request) { $this->validate($request, [ - 'role_id' => 'required', 'name' => 'required', 'ktp_number' => 'required|string|unique:m_users,ktp_number', 'employee_type' => 'required', 'company_id' => 'required', - 'username' => 'unique:m_users,username' + 'username' => 'unique:m_users,username', ]); $data = $request->all(); + !$request->is_customer ? $this->validate($request,['role_id'=>'required','divisi_id'=>'required']) : ''; if (isset($request->password) && $request->password != "") { $data['password'] = md5($request->password); @@ -113,6 +112,8 @@ class HumanResourceController extends Controller public function update(Request $request, $id) { + !$request->is_customer ? $this->validate($request,['role_id'=>'required','divisi_id'=>'required']) : ''; + if (!$id || (int) $id < 0 || $id == "") { return response()->json(['status' => 'failed', 'message' => 'Id is required!', 'code' => 400], 400); }