'datetime:Y-m-d H:i:s', 'out_date' => 'datetime:Y-m-d H:i:s', ]; // Фильтр по подразделению (получает ID отделений) public function scopeDepartment($query, int $departmentId) { $branchIds = DB::table('stt_stationarbranch') ->where('rf_DepartmentID', $departmentId) ->pluck('StationarBranchID'); return $query->whereIn('stationar_branch_id', $branchIds); } public function scopeCurrentMigration($query, $historyId, $departmentId) { return $query->where('medical_history_id', $historyId) ->department($departmentId) ->orderBy('ingoing_date', 'desc') ->limit(1)->first(); } }