'boolean', ]; /** @return BelongsTo */ public function quiz(): BelongsTo { return $this->belongsTo(Quiz::class); } /** @return HasMany */ public function choix(): HasMany { return $this->hasMany(ChoixQuestionQuiz::class)->orderBy('ordre'); } /** * Vrai si $choixId (QCM) ou $reponseVraiFaux (vrai/faux) est la bonne * réponse à cette question. Un seul des deux arguments compte, selon * le type de la question. */ public function estCorrecte(?int $choixId, ?bool $reponseVraiFaux): bool { if ($this->type === self::VRAI_FAUX) { return $reponseVraiFaux !== null && $reponseVraiFaux === $this->reponse_vrai_faux; } return $choixId !== null && $this->choix()->where('id', $choixId)->where('est_correct', true)->exists(); } }