Add Quiz feature: 10-question quizzes with progressive scoring (max 40 pts)

- Quizzes table with questions, answer options, attempts, answers
- Question types: multiple_choice, exclusion, true_false, free_text
- Progressive scoring: [1,1,2,2,3,3,4,6,8,10] = max 40 per quiz
- Alpine.js countdown timer per question with auto-submit on timeout
- Admin: CRUD for quizzes + per-question editor, JSON export/import
- Child: quiz overview with best scores, question view, result breakdown
- Nav: Quiz link in child header and admin sidebar
This commit is contained in:
root
2026-05-05 21:14:09 +00:00
parent 213d4b4832
commit 6c6dd26823
21 changed files with 984 additions and 1 deletions
@@ -0,0 +1,71 @@
@extends('layouts.admin')
@section('title','Frage hinzufügen')
@section('content')
<div class="max-w-2xl">
<a href="{{ route('admin.quizzes.edit',$quiz) }}" class="text-sm text-slate-500 hover:text-slate-700 mb-4 inline-block"> Zurück zu {{ $quiz->title }}</a>
<div class="bg-white rounded-xl shadow-sm border border-slate-200 p-6">
<h2 class="font-semibold text-slate-800 mb-5">Neue Frage hinzufügen</h2>
<form method="POST" action="{{ route('admin.quizzes.questions.store',$quiz) }}" class="space-y-4">
@csrf
@php $qtype='multiple_choice'; $correctIdx=0; $question_text=''; $time_limit=''; $correct_answer=''; $options=[]; @endphp
<div x-data="{ qtype: '{{ $qtype }}', correctIdx: {{ $correctIdx }} }">
<div>
<label class="block text-sm font-medium text-slate-700 mb-1">Fragetyp</label>
<select name="type" x-model="qtype" required
class="w-full border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-violet-500 outline-none">
<option value="multiple_choice">Multiple Choice Fehlersuche</option>
<option value="exclusion">Ausschlussverfahren (welches gehört nicht dazu?)</option>
<option value="true_false">Wahr / Falsch</option>
<option value="free_text">Freitext Eingabe</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-slate-700 mb-1">Frage</label>
<textarea name="question_text" required rows="3"
class="w-full border border-slate-300 rounded-lg px-3 py-2 text-sm font-medium focus:ring-2 focus:ring-violet-500 outline-none">{{ $question_text ?? '' }}</textarea>
</div>
<div>
<label class="block text-sm font-medium text-slate-700 mb-1">Zeitlimit in Sekunden (leer = kein Limit)</label>
<input name="time_limit" type="number" min="5" max="120" value="{{ $time_limit ?? '' }}" placeholder="z.B. 30"
class="w-32 border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-violet-500 outline-none">
</div>
{{-- MC / Exclusion options --}}
<div x-show="qtype === 'multiple_choice' || qtype === 'exclusion'" class="space-y-2">
<label class="block text-sm font-medium text-slate-700">Antwortmöglichkeiten <span class="text-slate-400 font-normal">( = richtige Antwort)</span></label>
@for($i = 0; $i < 4; $i++)
<div class="flex items-center gap-3">
<input type="radio" name="correct_option" value="{{ $i }}" x-bind:checked="correctIdx === {{ $i }}"
@change="correctIdx = {{ $i }}"
class="text-violet-600 w-4 h-4 shrink-0">
<input type="text" name="options[{{ $i }}][text]" value="{{ $options[$i]['text'] ?? '' }}"
placeholder="Option {{ $i+1 }}"
class="flex-1 border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-violet-500 outline-none">
</div>
@endfor
<p class="text-xs text-slate-400">Klicke den Radio-Button links neben der richtigen Antwort.</p>
</div>
{{-- True / False --}}
<div x-show="qtype === 'true_false'">
<label class="block text-sm font-medium text-slate-700 mb-1">Richtige Antwort</label>
<select name="correct_answer"
class="w-full border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-violet-500 outline-none">
<option value="true" {{ ($correct_answer ?? '') === 'true' ? 'selected' : '' }}> Wahr</option>
<option value="false" {{ ($correct_answer ?? '') === 'false' ? 'selected' : '' }}> Falsch</option>
</select>
</div>
{{-- Free text --}}
<div x-show="qtype === 'free_text'">
<label class="block text-sm font-medium text-slate-700 mb-1">Richtige Antwort (exakter Text, Groß-/Kleinschreibung egal)</label>
<input type="text" name="correct_answer" value="{{ $correct_answer ?? '' }}" placeholder="z.B. 72"
class="w-full border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-violet-500 outline-none">
</div>
</div>
<button type="submit" class="w-full bg-violet-600 hover:bg-violet-700 text-white py-2 rounded-lg font-medium text-sm">Frage hinzufügen</button>
</form>
</div>
</div>
@endsection
@@ -0,0 +1,80 @@
@extends('layouts.admin')
@section('title','Frage bearbeiten')
@section('content')
<div class="max-w-2xl">
<a href="{{ route('admin.quizzes.edit',$question->quiz) }}" class="text-sm text-slate-500 hover:text-slate-700 mb-4 inline-block"> Zurück zu {{ $question->quiz->title }}</a>
<div class="bg-white rounded-xl shadow-sm border border-slate-200 p-6">
<h2 class="font-semibold text-slate-800 mb-5">Frage bearbeiten</h2>
<form method="POST" action="{{ route('admin.quiz-questions.update',$question) }}" class="space-y-4">
@csrf @method('PUT')
@php
$qtype = $question->type;
$question_text = $question->question_text;
$time_limit = $question->time_limit;
$correct_answer = $question->correct_answer;
$opts = $question->answerOptions->toArray();
$options = array_column($opts, null);
$correctIdx = 0;
foreach ($opts as $i => $o) { if ($o['is_correct']) { $correctIdx = $i; break; } }
@endphp
<div x-data="{ qtype: '{{ $qtype }}', correctIdx: {{ $correctIdx }} }">
<div>
<label class="block text-sm font-medium text-slate-700 mb-1">Fragetyp</label>
<select name="type" x-model="qtype" required
class="w-full border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-violet-500 outline-none">
<option value="multiple_choice">Multiple Choice Fehlersuche</option>
<option value="exclusion">Ausschlussverfahren (welches gehört nicht dazu?)</option>
<option value="true_false">Wahr / Falsch</option>
<option value="free_text">Freitext Eingabe</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-slate-700 mb-1">Frage</label>
<textarea name="question_text" required rows="3"
class="w-full border border-slate-300 rounded-lg px-3 py-2 text-sm font-medium focus:ring-2 focus:ring-violet-500 outline-none">{{ $question_text ?? '' }}</textarea>
</div>
<div>
<label class="block text-sm font-medium text-slate-700 mb-1">Zeitlimit in Sekunden (leer = kein Limit)</label>
<input name="time_limit" type="number" min="5" max="120" value="{{ $time_limit ?? '' }}" placeholder="z.B. 30"
class="w-32 border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-violet-500 outline-none">
</div>
{{-- MC / Exclusion options --}}
<div x-show="qtype === 'multiple_choice' || qtype === 'exclusion'" class="space-y-2">
<label class="block text-sm font-medium text-slate-700">Antwortmöglichkeiten <span class="text-slate-400 font-normal">( = richtige Antwort)</span></label>
@for($i = 0; $i < 4; $i++)
<div class="flex items-center gap-3">
<input type="radio" name="correct_option" value="{{ $i }}" x-bind:checked="correctIdx === {{ $i }}"
@change="correctIdx = {{ $i }}"
class="text-violet-600 w-4 h-4 shrink-0">
<input type="text" name="options[{{ $i }}][text]" value="{{ $options[$i]['text'] ?? '' }}"
placeholder="Option {{ $i+1 }}"
class="flex-1 border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-violet-500 outline-none">
</div>
@endfor
<p class="text-xs text-slate-400">Klicke den Radio-Button links neben der richtigen Antwort.</p>
</div>
{{-- True / False --}}
<div x-show="qtype === 'true_false'">
<label class="block text-sm font-medium text-slate-700 mb-1">Richtige Antwort</label>
<select name="correct_answer"
class="w-full border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-violet-500 outline-none">
<option value="true" {{ ($correct_answer ?? '') === 'true' ? 'selected' : '' }}> Wahr</option>
<option value="false" {{ ($correct_answer ?? '') === 'false' ? 'selected' : '' }}> Falsch</option>
</select>
</div>
{{-- Free text --}}
<div x-show="qtype === 'free_text'">
<label class="block text-sm font-medium text-slate-700 mb-1">Richtige Antwort (exakter Text, Groß-/Kleinschreibung egal)</label>
<input type="text" name="correct_answer" value="{{ $correct_answer ?? '' }}" placeholder="z.B. 72"
class="w-full border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-violet-500 outline-none">
</div>
</div>
<button type="submit" class="w-full bg-violet-600 hover:bg-violet-700 text-white py-2 rounded-lg font-medium text-sm">Speichern</button>
</form>
</div>
</div>
@endsection
@@ -0,0 +1,28 @@
@extends('layouts.admin')
@section('title','Neues Quiz')
@section('content')
<div class="max-w-xl">
<a href="{{ route('admin.quizzes.index') }}" class="text-sm text-slate-500 hover:text-slate-700 mb-4 inline-block"> Zurück</a>
<div class="bg-white rounded-xl shadow-sm border border-slate-200 p-6">
<h2 class="font-semibold text-slate-800 mb-5">Neues Quiz</h2>
<form method="POST" action="{{ route('admin.quizzes.store') }}" class="space-y-4">
@csrf
<div>
<label class="block text-sm font-medium text-slate-700 mb-1">Fach</label>
<select name="subject_id" required class="w-full border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-violet-500 outline-none">
@foreach($subjects as $s)<option value="{{ $s->id }}">{{ $s->icon }} {{ $s->name }}</option>@endforeach
</select>
</div>
<div>
<label class="block text-sm font-medium text-slate-700 mb-1">Titel</label>
<input name="title" required value="{{ old('title') }}" class="w-full border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-violet-500 outline-none">
</div>
<div>
<label class="block text-sm font-medium text-slate-700 mb-1">Beschreibung (optional)</label>
<textarea name="description" rows="2" class="w-full border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-violet-500 outline-none">{{ old('description') }}</textarea>
</div>
<button type="submit" class="w-full bg-violet-600 hover:bg-violet-700 text-white py-2 rounded-lg font-medium text-sm">Erstellen & Fragen hinzufügen </button>
</form>
</div>
</div>
@endsection
@@ -0,0 +1,72 @@
@extends('layouts.admin')
@section('title','Quiz bearbeiten')
@section('content')
<div class="max-w-3xl">
<a href="{{ route('admin.quizzes.index') }}" class="text-sm text-slate-500 hover:text-slate-700 mb-4 inline-block"> Zurück</a>
{{-- Metadata --}}
<div class="bg-white rounded-xl shadow-sm border border-slate-200 p-6 mb-6">
<h2 class="font-semibold text-slate-800 mb-5">Quiz-Einstellungen</h2>
<form method="POST" action="{{ route('admin.quizzes.update',$quiz) }}" class="space-y-4">
@csrf @method('PUT')
<div class="grid grid-cols-3 gap-4">
<div>
<label class="block text-sm font-medium text-slate-700 mb-1">Fach</label>
<select name="subject_id" required class="w-full border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-violet-500 outline-none">
@foreach($subjects as $s)<option value="{{ $s->id }}" {{ $s->id==$quiz->subject_id?'selected':'' }}>{{ $s->icon }} {{ $s->name }}</option>@endforeach
</select>
</div>
<div class="col-span-2">
<label class="block text-sm font-medium text-slate-700 mb-1">Titel</label>
<input name="title" required value="{{ $quiz->title }}" class="w-full border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-violet-500 outline-none">
</div>
</div>
<div>
<label class="block text-sm font-medium text-slate-700 mb-1">Beschreibung</label>
<textarea name="description" rows="2" class="w-full border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-violet-500 outline-none">{{ $quiz->description }}</textarea>
</div>
<div class="flex items-center gap-2">
<input type="checkbox" name="active" id="active" value="1" {{ $quiz->active?'checked':'' }} class="w-4 h-4 text-violet-600">
<label for="active" class="text-sm text-slate-700">Quiz aktiv (für Kinder sichtbar)</label>
</div>
<button type="submit" class="bg-violet-600 hover:bg-violet-700 text-white px-6 py-2 rounded-lg font-medium text-sm">Speichern</button>
</form>
</div>
{{-- Questions --}}
<div class="flex justify-between items-center mb-3">
<h3 class="font-semibold text-slate-700">Fragen
<span class="{{ $questions->count() < 10 ? 'text-amber-500' : 'text-green-600' }} font-normal text-sm ml-1">({{ $questions->count() }}/10)</span>
</h3>
@if($questions->count() < 10)
<a href="{{ route('admin.quizzes.questions.create',$quiz) }}" class="bg-violet-600 hover:bg-violet-700 text-white px-4 py-2 rounded-lg text-sm font-medium">+ Frage hinzufügen</a>
@else
<span class="text-green-600 text-sm font-medium"> 10 Fragen vollständig</span>
@endif
</div>
@forelse($questions as $i => $q)
<div class="bg-white rounded-xl border border-slate-200 px-4 py-3 mb-2 flex items-start justify-between gap-4 hover:bg-slate-50">
<div class="flex items-start gap-3 flex-1 min-w-0">
<span class="text-slate-400 text-sm pt-0.5 shrink-0">{{ $i+1 }}.</span>
<div class="min-w-0">
<span class="text-xs bg-slate-100 text-slate-500 px-2 py-0.5 rounded mr-2">{{ $q->typeLabel() }}</span>
@if($q->time_limit)<span class="text-xs text-amber-600 mr-2"> {{ $q->time_limit }}s</span>@endif
<p class="text-sm text-slate-700 mt-1 line-clamp-2">{{ $q->question_text }}</p>
</div>
</div>
<div class="flex gap-3 text-sm shrink-0">
<a href="{{ route('admin.quiz-questions.edit',$q) }}" class="text-violet-600 hover:underline">Bearbeiten</a>
<form method="POST" action="{{ route('admin.quiz-questions.destroy',$q) }}" class="inline" onsubmit="return confirm('Frage löschen?')">
@csrf @method('DELETE')
<button class="text-red-500 hover:underline">Löschen</button>
</form>
</div>
</div>
@empty
<div class="bg-slate-50 rounded-xl border border-dashed border-slate-300 p-8 text-center text-slate-400 text-sm">
Noch keine Fragen. Füge bis zu 10 Fragen hinzu.
</div>
@endforelse
</div>
@endsection
@@ -0,0 +1,61 @@
@extends('layouts.admin')
@section('title','Quizzes')
@section('content')
<div class="flex justify-between items-center mb-6" x-data="{showImport:false}">
<h2 class="text-lg font-semibold text-slate-700">Quizzes</h2>
<div class="flex gap-2">
<button @click="showImport=!showImport"
class="flex items-center gap-1.5 bg-slate-100 hover:bg-slate-200 text-slate-700 px-3 py-2 rounded-lg text-sm font-medium"
:class="showImport && 'bg-amber-100 text-amber-700'"> Import</button>
<a href="{{ route('admin.quizzes.create') }}" class="bg-violet-600 hover:bg-violet-700 text-white px-4 py-2 rounded-lg text-sm font-medium">+ Neues Quiz</a>
</div>
<div x-show="showImport" x-cloak class="w-full mt-3">
<div class="bg-amber-50 border border-amber-200 rounded-xl p-4">
<p class="text-xs text-slate-500 mb-3">JSON im gleichen Format wie der Export. Erstellt immer ein neues Quiz.</p>
<form method="POST" action="{{ route('admin.quizzes.import') }}" enctype="multipart/form-data" class="flex gap-3">
@csrf
<input type="file" name="file" accept=".json" required
class="flex-1 text-sm text-slate-600 file:mr-3 file:py-1.5 file:px-3 file:rounded-lg file:border-0 file:text-sm file:font-medium file:bg-violet-100 file:text-violet-700">
<button type="submit" class="bg-violet-600 hover:bg-violet-700 text-white px-4 py-2 rounded-lg text-sm font-medium whitespace-nowrap">Importieren</button>
</form>
</div>
</div>
</div>
<div class="bg-white rounded-xl shadow-sm border border-slate-200 overflow-hidden">
<table class="w-full text-sm">
<thead class="bg-slate-50 border-b border-slate-200">
<tr>
<th class="text-left px-4 py-3 font-medium text-slate-600">Fach</th>
<th class="text-left px-4 py-3 font-medium text-slate-600">Titel</th>
<th class="text-center px-4 py-3 font-medium text-slate-600">Fragen</th>
<th class="text-center px-4 py-3 font-medium text-slate-600">Status</th>
<th class="px-4 py-3"></th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100">
@forelse($quizzes as $quiz)
<tr class="hover:bg-slate-50">
<td class="px-4 py-3 text-slate-600">{{ $quiz->subject->icon }} {{ $quiz->subject->name }}</td>
<td class="px-4 py-3 font-medium text-slate-800">{{ $quiz->title }}</td>
<td class="px-4 py-3 text-center">
<span class="{{ $quiz->questions_count < 10 ? 'text-amber-600' : 'text-green-600' }} font-medium">
{{ $quiz->questions_count }}/10
</span>
</td>
<td class="px-4 py-3 text-center">{{ $quiz->active ? '✅' : '⏸️' }}</td>
<td class="px-4 py-3 text-right whitespace-nowrap">
<a href="{{ route('admin.quizzes.export',$quiz) }}" class="text-slate-500 hover:text-slate-700 mr-3 text-xs"> Export</a>
<a href="{{ route('admin.quizzes.edit',$quiz) }}" class="text-violet-600 hover:underline mr-3">Bearbeiten</a>
<form method="POST" action="{{ route('admin.quizzes.destroy',$quiz) }}" class="inline" onsubmit="return confirm('Quiz löschen?')">
@csrf @method('DELETE')
<button class="text-red-500 hover:underline">Löschen</button>
</form>
</td>
</tr>
@empty
<tr><td colspan="5" class="px-4 py-10 text-center text-slate-400">Noch keine Quizzes. <a href="{{ route('admin.quizzes.create') }}" class="text-violet-600 hover:underline">Erstes Quiz erstellen </a></td></tr>
@endforelse
</tbody>
</table>
</div>
@endsection
@@ -0,0 +1,46 @@
@extends('layouts.child')
@section('content')
<h1 class="text-2xl font-bold text-indigo-700 mb-2">🧠 Quiz</h1>
<p class="text-slate-500 mb-6">Beantworte 10 Fragen max. 40 Münzen zu gewinnen!</p>
@foreach($subjects as $subjectId => $subject)
@php $group = $quizzes->get($subjectId, collect()) @endphp
@if($group->isNotEmpty())
<div class="mb-6">
<h2 class="font-bold text-slate-600 text-sm uppercase tracking-wide mb-3">{{ $subject->icon }} {{ $subject->name }}</h2>
<div class="grid gap-3">
@foreach($group as $quiz)
<div class="bg-white rounded-2xl border border-slate-200 shadow-sm px-5 py-4">
<div class="flex items-start justify-between gap-4">
<div class="flex-1 min-w-0">
<h3 class="font-bold text-slate-800 text-base">{{ $quiz->title }}</h3>
@if($quiz->description)<p class="text-sm text-slate-500 mt-0.5">{{ $quiz->description }}</p>@endif
<div class="flex items-center gap-3 mt-2 text-xs text-slate-400">
<span>📝 {{ $quiz->questions_count }} Fragen</span>
<span>🏆 max. 40 Münzen</span>
@if(isset($bestScores[$quiz->id]))
<span class="text-amber-600 font-medium">Bisher: {{ $bestScores[$quiz->id] }}/40 🪙</span>
@endif
</div>
</div>
<form method="POST" action="{{ route('quiz.start',$quiz) }}">
@csrf
<button class="bg-indigo-600 hover:bg-indigo-700 text-white px-5 py-2.5 rounded-xl text-sm font-bold whitespace-nowrap">
{{ isset($bestScores[$quiz->id]) ? 'Nochmal' : 'Starten' }}
</button>
</form>
</div>
</div>
@endforeach
</div>
</div>
@endif
@endforeach
@if($quizzes->isEmpty())
<div class="text-center py-16 text-slate-400">
<p class="text-4xl mb-3">🧩</p>
<p>Noch keine Quizzes verfügbar. Schau später nochmal vorbei!</p>
</div>
@endif
@endsection
@@ -0,0 +1,123 @@
@extends('layouts.child')
@section('content')
@php $tl = $question->time_limit ?? 0; @endphp
<div x-data="{
tl: {{ $tl }},
left: {{ $tl }},
timedOut: false,
timer: null,
init() {
if (this.tl > 0) {
this.timer = setInterval(() => {
this.left--;
if (this.left <= 0) {
clearInterval(this.timer);
this.timedOut = true;
this.$nextTick(() => {
document.querySelectorAll('[required]').forEach(e => e.removeAttribute('required'));
document.getElementById('timeout-input').value = '1';
document.getElementById('answer-form').submit();
});
}
}, 1000);
}
}
}">
{{-- Header bar --}}
<div class="flex items-center gap-3 mb-4">
<a href="{{ route('quiz.index') }}" class="text-slate-400 hover:text-slate-600 text-sm"> Quiz</a>
<div class="flex-1 bg-slate-200 rounded-full h-2.5">
<div class="bg-violet-500 h-2.5 rounded-full transition-all duration-300"
style="width: {{ ($attempt->current_question / max($attempt->quiz->questions()->count(),1)) * 100 }}%"></div>
</div>
<span class="text-sm font-semibold text-slate-600 whitespace-nowrap">
{{ $attempt->current_question + 1 }} / {{ $attempt->quiz->questions()->count() }}
</span>
</div>
{{-- Timer bar --}}
<template x-if="tl > 0">
<div class="mb-4">
<div class="bg-slate-200 rounded-full h-2">
<div class="h-2 rounded-full transition-all duration-1000"
:class="left > tl*0.5 ? 'bg-green-500' : (left > tl*0.25 ? 'bg-yellow-500' : 'bg-red-500')"
:style="'width:' + Math.max(0,(left/tl)*100) + '%'"></div>
</div>
<div class="text-right text-xs mt-1" :class="left <= 5 ? 'text-red-500 font-bold' : 'text-slate-400'">
<span x-text="left"></span>s
</div>
</div>
</template>
{{-- Last answer flash --}}
@if(session('last_answer'))
@php $la = session('last_answer'); @endphp
<div class="mb-4 rounded-xl px-4 py-3 text-sm font-medium flex items-center gap-2
{{ $la['timeout'] ? 'bg-slate-100 text-slate-600' : ($la['correct'] ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-700') }}">
@if($la['timeout']) Zeit abgelaufen 0 Münzen
@elseif($la['correct']) Richtig! +{{ $la['points'] }} 🪙
@else Leider falsch 0 Münzen
@endif
</div>
@endif
{{-- Points badge --}}
<div class="text-center mb-5">
<span class="bg-amber-100 text-amber-700 text-sm font-bold px-4 py-1.5 rounded-full">
+{{ $pointsIfCorrect }} 🪙 bei richtiger Antwort
</span>
</div>
{{-- Question card --}}
<div class="bg-white rounded-2xl shadow-sm border border-slate-200 p-6">
<h2 class="text-xl font-black text-slate-800 mb-6 leading-snug">{{ $question->question_text }}</h2>
<form method="POST" action="{{ route('quiz.answer',$attempt) }}" id="answer-form">
@csrf
<input type="hidden" name="timeout" value="0" id="timeout-input">
@if(in_array($question->type, ['multiple_choice','exclusion']))
<div class="grid grid-cols-2 gap-3 mb-6">
@foreach($question->answerOptions as $opt)
<label class="flex items-center gap-3 p-4 border-2 border-slate-200 rounded-xl cursor-pointer
hover:border-violet-300 hover:bg-violet-50 has-[:checked]:border-violet-500 has-[:checked]:bg-violet-50
transition-colors">
<input type="radio" name="answer" value="{{ $opt->id }}" required class="w-4 h-4 text-violet-600 shrink-0">
<span class="text-slate-700 font-medium text-sm">{{ $opt->text }}</span>
</label>
@endforeach
</div>
@elseif($question->type === 'true_false')
<div class="grid grid-cols-2 gap-4 mb-6">
<label class="flex items-center justify-center gap-3 p-5 border-2 border-slate-200 rounded-xl cursor-pointer
hover:border-green-400 hover:bg-green-50 has-[:checked]:border-green-500 has-[:checked]:bg-green-50
transition-colors">
<input type="radio" name="answer" value="true" required class="sr-only">
<span class="text-2xl"></span>
<span class="font-bold text-slate-700">Wahr</span>
</label>
<label class="flex items-center justify-center gap-3 p-5 border-2 border-slate-200 rounded-xl cursor-pointer
hover:border-red-400 hover:bg-red-50 has-[:checked]:border-red-500 has-[:checked]:bg-red-50
transition-colors">
<input type="radio" name="answer" value="false" required class="sr-only">
<span class="text-2xl"></span>
<span class="font-bold text-slate-700">Falsch</span>
</label>
</div>
@elseif($question->type === 'free_text')
<div class="mb-6">
<input type="text" name="answer" required autofocus placeholder="Deine Antwort eingeben …"
class="w-full border-2 border-slate-200 focus:border-violet-500 rounded-xl px-4 py-3 text-lg font-bold text-slate-800 outline-none text-center transition-colors">
</div>
@endif
<button type="submit" class="w-full bg-violet-600 hover:bg-violet-700 text-white py-3 rounded-xl font-bold text-base">
Antworten
</button>
</form>
</div>
</div>
@endsection
@@ -0,0 +1,63 @@
@extends('layouts.child')
@section('content')
<div class="text-center mb-8">
<div class="text-6xl mb-3">{{ $attempt->stars() }}</div>
<h1 class="text-3xl font-black text-slate-800">{{ $attempt->score }} / 40 Münzen</h1>
<p class="text-slate-500 mt-1">{{ $attempt->quiz->title }}</p>
<div class="mt-3 inline-flex items-center gap-2 bg-amber-100 text-amber-700 font-bold px-5 py-2 rounded-full text-lg">
+{{ $attempt->score }} 🪙 verdient!
</div>
</div>
{{-- Per-question breakdown --}}
<div class="bg-white rounded-2xl shadow-sm border border-slate-200 overflow-hidden mb-6">
<table class="w-full text-sm">
<thead class="bg-slate-50 border-b border-slate-100">
<tr>
<th class="px-4 py-3 text-left font-medium text-slate-500">#</th>
<th class="px-4 py-3 text-left font-medium text-slate-500">Frage</th>
<th class="px-4 py-3 text-center font-medium text-slate-500">Ergebnis</th>
<th class="px-4 py-3 text-center font-medium text-slate-500">Münzen</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100">
@foreach($answers as $i => $a)
@php
$display = $a->answer_given;
if ($display === '__timeout__') {
$display = '⏱ Zeit abgelaufen';
} elseif (in_array($a->question->type, ['multiple_choice','exclusion'])) {
$opt = $a->question->answerOptions->firstWhere('id', (int)$a->answer_given);
$display = $opt ? $opt->text : '';
} elseif ($a->question->type === 'true_false') {
$display = $display === 'true' ? 'Wahr' : 'Falsch';
}
$points_scale = \App\Models\QuizAttempt::POINTS;
@endphp
<tr class="{{ $a->is_correct ? 'bg-green-50' : '' }}">
<td class="px-4 py-3 text-slate-400 font-medium">{{ $i+1 }}</td>
<td class="px-4 py-3 text-slate-700">{{ Str::limit($a->question->question_text, 55) }}</td>
<td class="px-4 py-3 text-center">
@if($a->is_correct)
<span class="text-green-700 font-medium"> {{ $display }}</span>
@else
<span class="text-red-600"> {{ $display }}</span>
@endif
</td>
<td class="px-4 py-3 text-center font-bold {{ $a->is_correct ? 'text-amber-600' : 'text-slate-300' }}">
{{ $a->is_correct ? '+' . $a->points_earned : '0' }}
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="flex gap-3">
<form method="POST" action="{{ route('quiz.start',$attempt->quiz) }}" class="flex-1">
@csrf
<button class="w-full bg-slate-100 hover:bg-slate-200 text-slate-700 py-3 rounded-xl font-medium">🔁 Nochmal spielen</button>
</form>
<a href="{{ route('quiz.index') }}" class="flex-1 bg-indigo-600 hover:bg-indigo-700 text-white py-3 rounded-xl font-bold text-center"> Zur Quiz-Übersicht</a>
</div>
@endsection
+3
View File
@@ -23,6 +23,9 @@
<a href="{{ route('admin.questions.index') }}" class="flex items-center gap-3 px-3 py-2 rounded-lg {{ request()->routeIs('admin.questions.*') ? 'bg-violet-600 text-white' : 'text-slate-300 hover:bg-slate-800' }}">
<span></span> Fragen
</a>
<a href="{{ route('admin.quizzes.index') }}" class="flex items-center gap-3 px-3 py-2 rounded-lg {{ request()->routeIs('admin.quizzes.*','admin.quiz-questions.*') ? 'bg-violet-600 text-white' : 'text-slate-300 hover:bg-slate-800' }}">
<span>🧠</span> Quizzes
</a>
<a href="{{ route('admin.rewards.index') }}" class="flex items-center gap-3 px-3 py-2 rounded-lg {{ request()->routeIs('admin.rewards.*') ? 'bg-violet-600 text-white' : 'text-slate-300 hover:bg-slate-800' }}">
<span>🎁</span> Belohnungen
</a>
+1
View File
@@ -13,6 +13,7 @@
</a>
<div class="flex items-center gap-4">
<a href="{{ route('learn.subjects') }}" class="text-sm font-medium text-slate-600 hover:text-indigo-600">Lernen</a>
<a href="{{ route('quiz.index') }}" class="text-sm font-medium text-slate-600 hover:text-indigo-600">🧠 Quiz</a>
<a href="{{ route('rewards.index') }}" class="text-sm font-medium text-slate-600 hover:text-indigo-600">🪙 Belohnungen</a>
<a href="{{ route('reference.index') }}" class="text-sm font-medium text-slate-600 hover:text-indigo-600">💡 Erinnerung</a>
<div class="flex items-center gap-1 bg-amber-100 text-amber-700 font-bold rounded-full px-3 py-1 text-sm">