From c74d8e14ec33dd6d76f61125b8329df9b6319c64 Mon Sep 17 00:00:00 2001 From: jeremy bayse Date: Tue, 14 Apr 2026 19:49:12 +0200 Subject: [PATCH] fix: null quiz crash in admin candidate show - load attempts.quiz withoutGlobalScopes + null guard in Vue template --- app/Http/Controllers/CandidateController.php | 16 +++++++++++++--- resources/js/Pages/Admin/Candidates/Show.vue | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/CandidateController.php b/app/Http/Controllers/CandidateController.php index e3ca269..d36bc48 100644 --- a/app/Http/Controllers/CandidateController.php +++ b/app/Http/Controllers/CandidateController.php @@ -81,13 +81,23 @@ class CandidateController extends Controller $candidate->load([ 'user', 'documents', - 'attempts.quiz', - 'attempts.answers.question', - 'attempts.answers.option', 'jobPosition', 'tenant' ]); + // Load attempts with quiz bypassing tenant scope + // (admin may view candidates whose quizzes belong to other tenants) + $candidate->setRelation( + 'attempts', + $candidate->attempts() + ->with([ + 'quiz' => fn($q) => $q->withoutGlobalScopes(), + 'answers.question', + 'answers.option', + ]) + ->get() + ); + $data = [ 'candidate' => $candidate, 'jobPositions' => \App\Models\JobPosition::all(), diff --git a/resources/js/Pages/Admin/Candidates/Show.vue b/resources/js/Pages/Admin/Candidates/Show.vue index 0d9c1ce..7f9342a 100644 --- a/resources/js/Pages/Admin/Candidates/Show.vue +++ b/resources/js/Pages/Admin/Candidates/Show.vue @@ -818,7 +818,7 @@ const runAI = async () => {
-

{{ attempt.quiz.title }}

+

{{ attempt.quiz?.title ?? 'Quiz supprimé' }}

Fini le {{ formatDateTime(attempt.finished_at) }}