'date:Y-m-d', 'review_date' => 'date:Y-m-d', 'completion_date' => 'date:Y-m-d', 'is_active' => 'boolean', ]; protected $attributes = [ 'is_active' => true, 'status' => self::STATUS_PENDING, ]; // ========================================================================= // 관계 정의 // ========================================================================= /** * 현장 */ public function site(): BelongsTo { return $this->belongsTo(Site::class, 'site_id'); } /** * 생성자 */ public function creator(): BelongsTo { return $this->belongsTo(User::class, 'created_by'); } /** * 수정자 */ public function updater(): BelongsTo { return $this->belongsTo(User::class, 'updated_by'); } // ========================================================================= // 스코프 // ========================================================================= /** * 상태별 필터 */ public function scopeStatus($query, string $status) { return $query->where('status', $status); } /** * 현장별 필터 */ public function scopeSite($query, int $siteId) { return $query->where('site_id', $siteId); } /** * 거래처별 필터 */ public function scopePartner($query, int $partnerId) { return $query->where('partner_id', $partnerId); } // ========================================================================= // 헬퍼 메서드 // ========================================================================= /** * 상태 라벨 반환 */ public function getStatusLabelAttribute(): string { return match ($this->status) { self::STATUS_PENDING => '검토대기', self::STATUS_COMPLETED => '검토완료', default => $this->status, }; } /** * 검토대기 여부 */ public function isPending(): bool { return $this->status === self::STATUS_PENDING; } /** * 검토완료 여부 */ public function isCompleted(): bool { return $this->status === self::STATUS_COMPLETED; } }