belongsTo(Report::class, 'rf_report_id'); } public function medicalHistory() { return $this->belongsTo(MisMedicalHistory::class, 'rf_medicalhistory_id', 'MedicalHistoryID'); } // Скоупы для фильтрации public function scopeForReport($query, $reportId) { return $query->where('rf_report_id', $reportId); } public function scopeByPatientType($query, $type) { return $query->where('patient_type', $type); } public function scopeByDepartment($query, $departmentId) { return $query->whereHas('medicalHistory.migrations.branch', function($q) use ($departmentId) { $q->where('rf_DepartmentID', $departmentId); }); } }