'array', ]; public function isCorrect() { if(empty($this->answer)) return false; if($this->question->type == 'text') { $correctAnswer = trim(strtolower($this->question->correct_answers[0])); $answer = trim(strtolower($this->answer[0])); return $correctAnswer == $answer; } if($this->question->type == 'single') { $correctAnswer = intval($this->question->correct_answers[0]); $answer = intval($this->answer[0]); return $correctAnswer == $answer; } if($this->question->type == 'multiple') { $correctAnswers = collect($this->question->correct_answers)->map(fn($a) => (int)$a)->sort()->values()->all(); $answers = collect($this->answer)->map(fn($a) => (int)$a)->sort()->values()->all(); return $correctAnswers === $answers; } return false; } public function question() { return $this->belongsTo(Question::class); } public function userTest() { return $this->belongsTo(UserTest::class); } public function user() { return $this->belongsTo(User::class); } }