Files
sam-manage/app/Models/Documents/DocumentApproval.php
권혁성 c65d3f49dc feat: 문서 관리 시스템 MNG 관리자 패널 구현 (Phase 2)
- Document 관련 모델 4개 생성 (Document, DocumentApproval, DocumentData, DocumentAttachment)
- DocumentController 생성 (목록/생성/상세/수정 페이지)
- DocumentApiController 생성 (AJAX CRUD 처리)
- 문서 관리 뷰 3개 생성 (index, edit, show)
- 웹/API 라우트 등록

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 21:51:23 +09:00

95 lines
2.3 KiB
PHP

<?php
namespace App\Models\Documents;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class DocumentApproval extends Model
{
protected $table = 'document_approvals';
// 상태 상수
public const STATUS_PENDING = 'PENDING';
public const STATUS_APPROVED = 'APPROVED';
public const STATUS_REJECTED = 'REJECTED';
public const STATUS_LABELS = [
self::STATUS_PENDING => '대기',
self::STATUS_APPROVED => '승인',
self::STATUS_REJECTED => '반려',
];
protected $fillable = [
'document_id',
'user_id',
'step',
'role',
'status',
'comment',
'acted_at',
'created_by',
'updated_by',
];
protected $casts = [
'step' => 'integer',
'acted_at' => 'datetime',
];
// =========================================================================
// Relationships
// =========================================================================
public function document(): BelongsTo
{
return $this->belongsTo(Document::class);
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
// =========================================================================
// Accessors
// =========================================================================
public function getStatusLabelAttribute(): string
{
return self::STATUS_LABELS[$this->status] ?? $this->status;
}
public function getStatusColorAttribute(): string
{
return match ($this->status) {
self::STATUS_PENDING => 'yellow',
self::STATUS_APPROVED => 'green',
self::STATUS_REJECTED => 'red',
default => 'gray',
};
}
// =========================================================================
// Helper Methods
// =========================================================================
public function isPending(): bool
{
return $this->status === self::STATUS_PENDING;
}
public function isApproved(): bool
{
return $this->status === self::STATUS_APPROVED;
}
public function isRejected(): bool
{
return $this->status === self::STATUS_REJECTED;
}
}