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; } }