From bc3777ace50adc64234d650bef3034636deef797 Mon Sep 17 00:00:00 2001 From: hskwon Date: Mon, 24 Nov 2025 11:42:01 +0900 Subject: [PATCH] =?UTF-8?q?=ED=85=8C=EB=84=8C=ED=8A=B8=20CRUD=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 주요 수정사항: - UpdateTenantRequest: 라우트 파라미터 수정 (tenant → id) - TenantService: 영구 삭제 시 관련 데이터 먼저 삭제 (FK 제약 해결) - edit.blade.php: HTMX URL 전체 경로 사용 + 폼 fallback 추가 - index.blade.php: CSRF 토큰 추가 (삭제, 복원, 영구삭제) 버그 수정: - 수정 시 302 리다이렉트 오류 해결 (code 유일성 검증 실패) - 삭제 시 419 CSRF 토큰 오류 해결 - 영구 삭제 시 500 FK 제약 오류 해결 --- app/Http/Requests/UpdateTenantRequest.php | 2 +- app/Services/TenantService.php | 7 +++++++ resources/views/tenants/edit.blade.php | 7 +++++-- resources/views/tenants/index.blade.php | 25 +++++++++++++++++++++-- 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/app/Http/Requests/UpdateTenantRequest.php b/app/Http/Requests/UpdateTenantRequest.php index 8c5ad504..6c3bff03 100644 --- a/app/Http/Requests/UpdateTenantRequest.php +++ b/app/Http/Requests/UpdateTenantRequest.php @@ -20,7 +20,7 @@ public function authorize(): bool */ public function rules(): array { - $tenantId = $this->route('tenant'); + $tenantId = $this->route('id'); return [ // 기본 정보 (필수) diff --git a/app/Services/TenantService.php b/app/Services/TenantService.php index beea804b..7c05368e 100644 --- a/app/Services/TenantService.php +++ b/app/Services/TenantService.php @@ -104,6 +104,13 @@ public function restoreTenant(int $id): bool public function forceDeleteTenant(int $id): bool { $tenant = Tenant::withTrashed()->findOrFail($id); + + // 관련 데이터 먼저 삭제 + $tenant->users()->detach(); // user_tenants 관계 삭제 + $tenant->departments()->forceDelete(); // 부서 영구 삭제 + $tenant->menus()->forceDelete(); // 메뉴 영구 삭제 + $tenant->roles()->forceDelete(); // 역할 영구 삭제 + return $tenant->forceDelete(); } diff --git a/resources/views/tenants/edit.blade.php b/resources/views/tenants/edit.blade.php index 6e5ae4b0..c1b6c169 100644 --- a/resources/views/tenants/edit.blade.php +++ b/resources/views/tenants/edit.blade.php @@ -15,9 +15,13 @@
+ @method('PUT') + @csrf
@@ -186,7 +190,6 @@ class="px-6 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition" @endsection @push('scripts') -