fix: bypass tenant scope in recalculateScore - null quiz when candidate finishes quiz

This commit is contained in:
jeremy bayse
2026-04-14 19:35:26 +02:00
parent 479a7e35d1
commit 49ee91c601

View File

@@ -142,12 +142,21 @@ class AttemptController extends Controller
private function recalculateScore(Attempt $attempt) private function recalculateScore(Attempt $attempt)
{ {
$attempt->load(['quiz.questions.options', 'answers.option']); // Bypass tenant scope: candidates have no tenant_id
$quiz = Quiz::withoutGlobalScopes()
->with(['questions.options'])
->find($attempt->quiz_id);
$attempt->load(['answers.option']);
$score = 0; $score = 0;
$maxScore = 0; $maxScore = 0;
foreach ($attempt->quiz->questions as $question) { if (!$quiz) {
return;
}
foreach ($quiz->questions as $question) {
$maxScore += $question->points; $maxScore += $question->points;
$userAnswer = $attempt->answers->where('question_id', $question->id)->first(); $userAnswer = $attempt->answers->where('question_id', $question->id)->first();