runInTransaction( function () use ($user, $validated): void { $user->update([ 'email' => $validated['email'], 'username' => $validated['username'], ]); /** @var \App\Models\UserProfile $profile */ $profile = $user->profile()->updateOrCreate( ['user_id' => $user->id], [ 'full_name' => $validated['full_name'], 'phone_number' => $validated['phone_number'] ?? null, 'gender' => $validated['gender'] ?? null, 'birth_date' => $validated['birth_date'] ?? null, 'address' => $validated['address'] ?? null, ], ); $this->syncPhotos( $profile, [ 'photos' => $validated['profile_photo'] ?? null, 'remove_media_ids' => $validated['remove_profile_photo_ids'] ?? null, 's3_keys' => ! empty($validated['profile_s3_key']) ? [$validated['profile_s3_key']] : null, ], maxPhotos: 1, required: false, collection: 'profile_photo', ); }, 'Gagal memperbarui profil', ); } public function updatePassword(User $user, string $password): void { $user->update([ 'password' => Hash::make($password), ]); } }