From a8c33ee55ffbfb1f1f4eb1d4cf05942e126bd7e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=B3=B4=EA=B3=A4?= Date: Thu, 19 Mar 2026 21:55:28 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20[=EA=B7=BC=ED=83=9C=ED=98=84=ED=99=A9]?= =?UTF-8?q?=20soft-deleted=20attendance=20=EB=B3=B5=EC=9B=90=20=EC=8B=9C?= =?UTF-8?q?=20$fillable=20=EC=A0=9C=ED=95=9C=20=EB=AC=B8=EC=A0=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit deleted_at이 Attendance 모델 $fillable에 없어서 updateOrCreate()에서 deleted_at=null 설정이 무시되던 근본 원인 수정. restore() 메서드로 soft-delete 복원하도록 변경. --- app/Services/HR/AttendanceService.php | 12 ++++++++---- app/Services/HR/LeaveService.php | 10 +++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/Services/HR/AttendanceService.php b/app/Services/HR/AttendanceService.php index c2d79da2..2b72b8b2 100644 --- a/app/Services/HR/AttendanceService.php +++ b/app/Services/HR/AttendanceService.php @@ -158,8 +158,8 @@ private function syncApprovedLeaveAttendances(array $filters = []): void continue; } - // 누락된 attendance 레코드 생성 - Attendance::withTrashed()->updateOrCreate( + // 누락된 attendance 레코드 생성 (soft-deleted 포함 검색 → 복원) + $attendance = Attendance::withTrashed()->updateOrCreate( [ 'tenant_id' => $tenantId, 'user_id' => $leave->user_id, @@ -169,11 +169,15 @@ private function syncApprovedLeaveAttendances(array $filters = []): void 'status' => $attendanceStatus, 'remarks' => $leave->reason ? mb_substr($leave->reason, 0, 100) : null, 'updated_by' => $leave->approved_by, - 'deleted_at' => null, - 'deleted_by' => null, ] ); + // deleted_at은 $fillable에 없으므로 restore()로 복원 + if ($attendance->trashed()) { + $attendance->restore(); + $attendance->update(['deleted_by' => null]); + } + $existingKeys[$key] = true; } } diff --git a/app/Services/HR/LeaveService.php b/app/Services/HR/LeaveService.php index 51bc6b1a..2502d9b7 100644 --- a/app/Services/HR/LeaveService.php +++ b/app/Services/HR/LeaveService.php @@ -1184,7 +1184,7 @@ private function createAttendanceRecords(Leave $leave, int $tenantId, string $st continue; } - Attendance::withTrashed()->updateOrCreate( + $attendance = Attendance::withTrashed()->updateOrCreate( [ 'tenant_id' => $tenantId, 'user_id' => $leave->user_id, @@ -1194,10 +1194,14 @@ private function createAttendanceRecords(Leave $leave, int $tenantId, string $st 'status' => $status, 'remarks' => $leave->reason ? mb_substr($leave->reason, 0, 100) : null, 'updated_by' => auth()->id(), - 'deleted_at' => null, - 'deleted_by' => null, ] ); + + // deleted_at은 $fillable에 없으므로 restore()로 복원 + if ($attendance->trashed()) { + $attendance->restore(); + $attendance->update(['deleted_by' => null]); + } } }