From b284e235d4bf063a6f1e87793d69969bed5c82cb Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Mon, 3 Apr 2023 13:06:49 +0700 Subject: [PATCH] Task #860q7btm6 cek username --- app/Http/Controllers/HumanResourceController.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Http/Controllers/HumanResourceController.php b/app/Http/Controllers/HumanResourceController.php index 2d372ff..0defd38 100644 --- a/app/Http/Controllers/HumanResourceController.php +++ b/app/Http/Controllers/HumanResourceController.php @@ -60,6 +60,10 @@ class HumanResourceController extends Controller if(isset($request->password) && $request->password!="" ){ $data['password'] = md5($request->password); } + + if(isset($data['username']) && HumanResource::where('username', $data['username'])->where('id', '<>', $id)->exists()){ + return response()->json(['status'=>'failed','message'=>'Username already exists!','code'=>400], 400); + } if($humanresource){ $result = $humanresource->update($data);