'string', ]; public function getFullNameAttribute() { return "$this->FAMILY $this->Name $this->OT"; } public function archiveHistory() { return $this->hasMany(ArchiveHistory::class, 'mis_history_id', 'MedicalHistoryID'); } public function archiveInfo() { return $this->hasOne(ArchiveInfo::class, 'mis_history_id', 'MedicalHistoryID'); } /** * Проверяет, можно ли выдать эту карту */ public function canBeIssued(): bool { // Проверяем, есть ли открытые выдачи $hasOpenIssue = $this->archiveHistory() ->whereNotNull('issue_at') ->whereNull('return_at') ->where('has_lost', false) ->exists(); $hasNotBadStatus = $this->archiveInfo() ->whereNotNull('status_id') ->whereNot('status_id', 3) ->whereNot('status_id', 4) ->exists(); return ($hasOpenIssue !== true && $hasNotBadStatus === true); } /** * Получает текущую открытую выдачу (если есть) */ public function getCurrentIssue(): ?ArchiveHistory { return $this->archiveHistory() ->whereNotNull('issue_at') ->whereNull('return_at') ->where('has_lost', false) ->latest('issue_at') ->first(); } }