feat: Lernapp mit Mathe/Deutsch/Englisch, Münzsystem und Belohnungen
This commit is contained in:
@@ -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'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user