'array', 'start_date' => 'date', 'end_date' => 'date', 'notify_delegator' => 'boolean', 'is_active' => 'boolean', ]; protected $fillable = [ 'tenant_id', 'delegator_id', 'delegate_id', 'start_date', 'end_date', 'form_ids', 'notify_delegator', 'is_active', 'reason', 'created_by', ]; // ========================================================================= // 관계 정의 // ========================================================================= /** * 위임자 (원래 결재자) */ public function delegator(): BelongsTo { return $this->belongsTo(User::class, 'delegator_id'); } /** * 대리자 (대신 결재하는 사람) */ public function delegate(): BelongsTo { return $this->belongsTo(User::class, 'delegate_id'); } // ========================================================================= // 스코프 // ========================================================================= public function scopeForDelegator($query, int $userId) { return $query->where('delegator_id', $userId); } public function scopeCurrentlyActive($query) { $today = now()->toDateString(); return $query->active() ->where('start_date', '<=', $today) ->where('end_date', '>=', $today); } }