refactor: streamline user profile update process by replacing individual field assignments with updateOrCreate method

This commit is contained in:
Yoga Pangestu 2026-06-19 13:58:11 +07:00
parent 55b779c76e
commit 5b7da76fc8

View File

@ -107,13 +107,16 @@ public function update(User $user, array $validated): void
$user->username = $validated['username']; $user->username = $validated['username'];
$user->save(); $user->save();
$profile = $user->profile; $user->profile()->updateOrCreate(
$profile->full_name = $validated['full_name']; ['user_id' => $user->id],
$profile->phone_number = $validated['phone_number']; [
$profile->gender = $validated['gender']; 'full_name' => $validated['full_name'],
$profile->birth_date = $validated['birth_date']; 'phone_number' => $validated['phone_number'],
$profile->address = $validated['address']; 'gender' => $validated['gender'],
$profile->save(); 'birth_date' => $validated['birth_date'],
'address' => $validated['address'],
],
);
$hasEmployee = ! empty($validated['join_date']) && ! empty($validated['employment_status']) && ! empty($validated['base_salary']); $hasEmployee = ! empty($validated['join_date']) && ! empty($validated['employment_status']) && ! empty($validated['base_salary']);