주요 변경사항: - Spatie Laravel Permission 패키지 설치 (v6.23.0) - admin 프로젝트에서 필수 Traits 및 Scopes 복사 - ModelTrait, BelongsToTenant, HasTenantFilter, UppercaseAttributes - TenantScope - Tenant 모델 관계 수정 (hasMany → belongsToMany via user_tenants) - Tenant 모델 null 처리 추가 (status_label, created_at) - Laravel 12 bootstrap/app.php에 API 라우트 등록 - API 라우트 미들웨어 수정 (auth:sanctum → web,auth) - HTMX 라이브러리 및 CSRF 토큰 헤더 추가 ViewServiceProvider 수정: - 전역 View Composer의 $tenants 변수를 $globalTenants로 변경 - 페이지별 페이지네이션된 $tenants 변수와의 충돌 방지 - tenant-selector.blade.php에서 $globalTenants 사용 버그 수정: - Collection::hasPages() 오류 해결 (ViewComposer 변수 덮어쓰기 문제) - 테넌트 목록 무한 로딩 스피너 해결 - 500 Internal Server Error 해결
112 lines
4.3 KiB
PHP
112 lines
4.3 KiB
PHP
@extends('layouts.app')
|
|
|
|
@section('title', '테넌트 관리')
|
|
|
|
@section('content')
|
|
<!-- TENANT INDEX PAGE MARKER - 이것이 보이면 tenants/index.blade.php가 로드된 것입니다 -->
|
|
<div class="container mx-auto">
|
|
<!-- 페이지 헤더 -->
|
|
<div class="flex justify-between items-center mb-6">
|
|
<h1 class="text-2xl font-bold text-gray-800">🏢 테넌트 관리</h1>
|
|
<a href="{{ route('tenants.create') }}" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg transition">
|
|
+ 새 테넌트
|
|
</a>
|
|
</div>
|
|
|
|
<!-- 필터 영역 -->
|
|
<div class="bg-white rounded-lg shadow-sm p-4 mb-6">
|
|
<form id="filterForm" class="flex gap-4">
|
|
<!-- 검색 -->
|
|
<div class="flex-1">
|
|
<input type="text"
|
|
name="search"
|
|
placeholder="회사명, 코드, 이메일로 검색..."
|
|
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
|
|
</div>
|
|
|
|
<!-- 상태 필터 -->
|
|
<div class="w-48">
|
|
<select name="tenant_st_code" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
|
|
<option value="">전체 상태</option>
|
|
<option value="trial">트라이얼</option>
|
|
<option value="active">활성</option>
|
|
<option value="suspended">정지</option>
|
|
<option value="expired">만료</option>
|
|
</select>
|
|
</div>
|
|
|
|
<!-- 삭제된 항목 포함 -->
|
|
<div class="w-48">
|
|
<select name="trashed" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
|
|
<option value="">활성만</option>
|
|
<option value="with">삭제 포함</option>
|
|
<option value="only">삭제만</option>
|
|
</select>
|
|
</div>
|
|
|
|
<!-- 검색 버튼 -->
|
|
<button type="submit" class="bg-gray-600 hover:bg-gray-700 text-white px-6 py-2 rounded-lg transition">
|
|
검색
|
|
</button>
|
|
</form>
|
|
</div>
|
|
|
|
<!-- 테이블 영역 (HTMX로 로드) -->
|
|
<div id="tenant-table"
|
|
hx-get="/api/admin/tenants"
|
|
hx-trigger="load, filterSubmit from:body"
|
|
hx-include="#filterForm"
|
|
hx-headers='{"X-CSRF-TOKEN": "{{ csrf_token() }}"}'
|
|
class="bg-white rounded-lg shadow-sm overflow-hidden">
|
|
<!-- 로딩 스피너 -->
|
|
<div class="flex justify-center items-center p-12">
|
|
<div class="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@endsection
|
|
|
|
@push('scripts')
|
|
<script src="https://unpkg.com/htmx.org@1.9.10"></script>
|
|
<script>
|
|
// 폼 제출 시 HTMX 이벤트 트리거
|
|
document.getElementById('filterForm').addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
htmx.trigger('#tenant-table', 'filterSubmit');
|
|
});
|
|
|
|
// HTMX 응답 처리
|
|
document.body.addEventListener('htmx:afterSwap', function(event) {
|
|
if (event.detail.target.id === 'tenant-table') {
|
|
const response = JSON.parse(event.detail.xhr.response);
|
|
if (response.html) {
|
|
event.detail.target.innerHTML = response.html;
|
|
}
|
|
}
|
|
});
|
|
|
|
// 삭제 확인
|
|
window.confirmDelete = function(id, name) {
|
|
if (confirm(`"${name}" 테넌트를 삭제하시겠습니까?`)) {
|
|
htmx.ajax('DELETE', `/api/admin/tenants/${id}`, {
|
|
target: '#tenant-table',
|
|
swap: 'none'
|
|
}).then(() => {
|
|
htmx.trigger('#tenant-table', 'filterSubmit');
|
|
});
|
|
}
|
|
};
|
|
|
|
// 복원 확인
|
|
window.confirmRestore = function(id, name) {
|
|
if (confirm(`"${name}" 테넌트를 복원하시겠습니까?`)) {
|
|
htmx.ajax('POST', `/api/admin/tenants/${id}/restore`, {
|
|
target: '#tenant-table',
|
|
swap: 'none'
|
|
}).then(() => {
|
|
htmx.trigger('#tenant-table', 'filterSubmit');
|
|
});
|
|
}
|
|
};
|
|
</script>
|
|
@endpush |