'integer', 'acted_at' => 'datetime', ]; protected $attributes = [ 'step' => 1, 'status' => self::STATUS_PENDING, ]; // ========================================================================= // Relationships // ========================================================================= /** * 문서 */ public function document(): BelongsTo { return $this->belongsTo(Document::class); } /** * 결재자 */ public function user(): BelongsTo { return $this->belongsTo(User::class); } /** * 생성자 */ public function creator(): BelongsTo { return $this->belongsTo(User::class, 'created_by'); } // ========================================================================= // Scopes // ========================================================================= /** * 대기 중인 결재 */ public function scopePending($query) { return $query->where('status', self::STATUS_PENDING); } /** * 승인된 결재 */ public function scopeApproved($query) { return $query->where('status', self::STATUS_APPROVED); } /** * 반려된 결재 */ public function scopeRejected($query) { return $query->where('status', self::STATUS_REJECTED); } /** * 특정 사용자의 결재 */ public function scopeForUser($query, int $userId) { return $query->where('user_id', $userId); } // ========================================================================= // 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; } /** * 결재 처리 완료 여부 */ public function isProcessed(): bool { return ! $this->isPending(); } }