From 5b7da76fc83bad6094690e3111c1832aebcbe737 Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Fri, 19 Jun 2026 13:58:11 +0700 Subject: [PATCH] refactor: streamline user profile update process by replacing individual field assignments with updateOrCreate method --- app/Services/Hr/EmployeeService.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/Services/Hr/EmployeeService.php b/app/Services/Hr/EmployeeService.php index c967994..8cdc121 100644 --- a/app/Services/Hr/EmployeeService.php +++ b/app/Services/Hr/EmployeeService.php @@ -107,13 +107,16 @@ public function update(User $user, array $validated): void $user->username = $validated['username']; $user->save(); - $profile = $user->profile; - $profile->full_name = $validated['full_name']; - $profile->phone_number = $validated['phone_number']; - $profile->gender = $validated['gender']; - $profile->birth_date = $validated['birth_date']; - $profile->address = $validated['address']; - $profile->save(); + $user->profile()->updateOrCreate( + ['user_id' => $user->id], + [ + 'full_name' => $validated['full_name'], + 'phone_number' => $validated['phone_number'], + 'gender' => $validated['gender'], + 'birth_date' => $validated['birth_date'], + 'address' => $validated['address'], + ], + ); $hasEmployee = ! empty($validated['join_date']) && ! empty($validated['employment_status']) && ! empty($validated['base_salary']);