user(); $level = $user->level(); $streak = $user->currentStreak(); $subjects = Subject::withCount(['questions as total' => fn($q) => $q->where('active',true)])->get() ->map(function($s) use ($user) { $s->correct = QuestionAttempt::whereHas('question', fn($q) => $q->where('subject_id',$s->id)) ->where('user_id',$user->id)->where('is_correct',true)->count(); return $s; }); $recentAttempts = QuestionAttempt::with('question.subject') ->where('user_id',$user->id)->latest('id')->take(5)->get(); $pendingRedemptions = $user->redemptions()->where('status','pending')->count(); return view('child.dashboard', compact('user','level','streak','subjects','recentAttempts','pendingRedemptions')); } }