value . $facultySlug, now()->addDay(), function () use ($facultySlug) { return Faculty::query() ->where('slug', $facultySlug) ->first(); } ); // Кешируем список активных кафедр факультета $departments = Cache::remember( CacheKeys::DEPARTMENTS_PREFIX->value . 'active_' . $faculty->id, now()->addDay(), function () use ($faculty) { return DepartmentPreviewResource::collection( Department::query() ->where('is_active', true) ->where('faculty_id', $faculty->id) ->get() ); } ); $departmentModel = Cache::remember( CacheKeys::DEPARTMENT_PREFIX->value . $cacheKey, now()->addDay(), function () use ($departmentSlug) { return Department::query() ->where('slug', $departmentSlug) ->where('is_active', true) ->with([ 'faculty', 'workers.userDetail', 'teachers.userDetail', 'programs.directionStudy', 'seo' ]) ->firstOrFail(); } ); $seo = Cache::remember( CacheKeys::DEPARTMENT_PREFIX->value . 'seo_' . $cacheKey, now()->addDay(), function () use ($departmentModel) { return $this->seoPageProvider->getSeoForModel($departmentModel); } ); $department = new DepartmentResource($departmentModel); $directions = Cache::remember( CacheKeys::DEPARTMENT_PREFIX->value . 'directions_' . $cacheKey, now()->addDay(), function () use ($department) { return $this->groupProgramsByDirection($department->programs); } ); return Inertia::render('Client/Departments/Show', compact( 'department', 'departments', 'directions', 'seo', )); } private function groupProgramsByDirection(Collection $programs): Collection { // Группируем программы по имени направления return $programs->groupBy(function ($program) { return $program->directionStudy->code . " " . $program->directionStudy->name; // Используем имя направления как ключ }); } }