user(); abort_unless($guardian->students()->whereKey($student->id)->exists(), 403); $progress = $student->lessonProgress() ->with('lesson:id,title,course_id') ->latest('updated_at') ->limit(10) ->get() ->map(fn ($row): array => [ 'lesson_id' => $row->lesson_id, 'lesson_title' => $row->lesson?->title, 'watched_percentage' => $row->watched_percentage, 'completed' => $row->completed_at !== null, 'last_active_at' => $row->updated_at->toIso8601String(), ]); $weakestConcepts = $student->conceptMastery() ->with('concept:id,name') ->orderBy('mastery_score') ->limit(5) ->get() ->map(fn ($row): array => [ 'concept' => $row->concept?->name, 'mastery_score' => (float) $row->mastery_score, ]); $latestReport = $student->aiReports() ->where('type', 'weakness_analysis') ->latest() ->first(); return response()->json([ 'student' => [ 'id' => $student->id, 'name' => $student->name, ], 'lessons_progress' => $progress, 'weakest_concepts' => $weakestConcepts, 'latest_ai_summary' => $latestReport?->summary, ]); } }