feat: Lernapp mit Mathe/Deutsch/Englisch, Münzsystem und Belohnungen

This commit is contained in:
root
2026-05-05 14:41:09 +00:00
parent 21e40cd2da
commit bd1640994c
45 changed files with 1522 additions and 58 deletions
@@ -0,0 +1,22 @@
<?php
namespace App\Http\Controllers\Child;
use App\Http\Controllers\Controller;
use App\Models\Subject;
use App\Models\QuestionAttempt;
class DashboardController extends Controller {
public function index() {
$user = auth()->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'));
}
}