- ArchivedRecord, ArchivedRecordRelation 모델 추가 - ArchivedRecordService 추가 (읽기 전용) - 목록/상세 컨트롤러 및 뷰 구현 - HTMX 기반 테이블 필터링 및 페이지네이션 - 사이드바 메뉴 연결
91 lines
1.9 KiB
PHP
91 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Archives;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class ArchivedRecord extends Model
|
|
{
|
|
protected $table = 'archived_records';
|
|
|
|
protected $fillable = [
|
|
'record_type',
|
|
'original_id',
|
|
'main_data',
|
|
'schema_version',
|
|
'deleted_by',
|
|
'deleted_at',
|
|
'notes',
|
|
];
|
|
|
|
protected $casts = [
|
|
'main_data' => 'array',
|
|
'deleted_at' => 'datetime',
|
|
'original_id' => 'integer',
|
|
'deleted_by' => 'integer',
|
|
];
|
|
|
|
/**
|
|
* 관계: 삭제한 사용자
|
|
*/
|
|
public function deletedByUser(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'deleted_by');
|
|
}
|
|
|
|
/**
|
|
* 관계: 연관 테이블 데이터
|
|
*/
|
|
public function relations(): HasMany
|
|
{
|
|
return $this->hasMany(ArchivedRecordRelation::class, 'archived_record_id');
|
|
}
|
|
|
|
/**
|
|
* Scope: 테넌트 타입만
|
|
*/
|
|
public function scopeTenant($query)
|
|
{
|
|
return $query->where('record_type', 'tenant');
|
|
}
|
|
|
|
/**
|
|
* Scope: 사용자 타입만
|
|
*/
|
|
public function scopeUser($query)
|
|
{
|
|
return $query->where('record_type', 'user');
|
|
}
|
|
|
|
/**
|
|
* 레코드 타입 레이블
|
|
*/
|
|
public function getRecordTypeLabelAttribute(): string
|
|
{
|
|
return match ($this->record_type) {
|
|
'tenant' => '테넌트',
|
|
'user' => '사용자',
|
|
default => $this->record_type,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* 메인 데이터 요약
|
|
*/
|
|
public function getMainDataSummaryAttribute(): string
|
|
{
|
|
if (empty($this->main_data)) {
|
|
return '-';
|
|
}
|
|
|
|
$data = $this->main_data;
|
|
$name = $data['name'] ?? $data['title'] ?? '-';
|
|
$id = $data['id'] ?? $this->original_id;
|
|
|
|
return "{$name} (ID: {$id})";
|
|
}
|
|
}
|