Files
sam-api/app/Models/Documents/DocumentAttachment.php
권혁성 2bce30056d feat: 문서 관리 시스템 모델 생성 (Phase 1.2)
- Document 모델 (상태 관리, 다형성 연결, 결재 처리)
- DocumentApproval 모델 (결재 단계, 상태 처리)
- DocumentData 모델 (EAV 패턴 데이터 저장)
- DocumentAttachment 모델 (파일 첨부 연결)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 19:57:22 +09:00

145 lines
3.5 KiB
PHP

<?php
namespace App\Models\Documents;
use App\Models\Commons\File;
use App\Models\Members\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* 문서 첨부파일 모델
*
* @property int $id
* @property int $document_id
* @property int $file_id
* @property string $attachment_type 첨부 유형 (general, signature, image 등)
* @property string|null $description 설명
* @property int|null $created_by
* @property \Carbon\Carbon|null $created_at
* @property \Carbon\Carbon|null $updated_at
*/
class DocumentAttachment extends Model
{
protected $table = 'document_attachments';
// =========================================================================
// 첨부 유형 상수
// =========================================================================
public const TYPE_GENERAL = 'general';
public const TYPE_SIGNATURE = 'signature';
public const TYPE_IMAGE = 'image';
public const TYPE_REFERENCE = 'reference';
public const TYPES = [
self::TYPE_GENERAL,
self::TYPE_SIGNATURE,
self::TYPE_IMAGE,
self::TYPE_REFERENCE,
];
// =========================================================================
// Fillable & Casts
// =========================================================================
protected $fillable = [
'document_id',
'file_id',
'attachment_type',
'description',
'created_by',
];
protected $attributes = [
'attachment_type' => self::TYPE_GENERAL,
];
// =========================================================================
// Relationships
// =========================================================================
/**
* 문서
*/
public function document(): BelongsTo
{
return $this->belongsTo(Document::class);
}
/**
* 파일
*/
public function file(): BelongsTo
{
return $this->belongsTo(File::class);
}
/**
* 생성자
*/
public function creator(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by');
}
// =========================================================================
// Scopes
// =========================================================================
/**
* 특정 유형의 첨부파일
*/
public function scopeOfType($query, string $type)
{
return $query->where('attachment_type', $type);
}
/**
* 일반 첨부파일
*/
public function scopeGeneral($query)
{
return $query->where('attachment_type', self::TYPE_GENERAL);
}
/**
* 서명 첨부파일
*/
public function scopeSignatures($query)
{
return $query->where('attachment_type', self::TYPE_SIGNATURE);
}
/**
* 이미지 첨부파일
*/
public function scopeImages($query)
{
return $query->where('attachment_type', self::TYPE_IMAGE);
}
// =========================================================================
// Helper Methods
// =========================================================================
/**
* 서명 첨부파일 여부
*/
public function isSignature(): bool
{
return $this->attachment_type === self::TYPE_SIGNATURE;
}
/**
* 이미지 첨부파일 여부
*/
public function isImage(): bool
{
return $this->attachment_type === self::TYPE_IMAGE;
}
}