<?php

namespace App\Traits;

trait QuestionTrait
{
    public function checkAnswer($answers)
    {
        $correctAnswers = ! is_array($this->correct_answers) ? [$this->correct_answer] : $this->correct_answers;
        $givenAnswers = ! is_array($answers) ? [$answers] : $answers;
        ksort($correctAnswers);
        ksort($givenAnswers);
        if ($correctAnswers == $givenAnswers) {
            return true;
        }

        return false;
    }
}
