多个复选框,答案

时间:2017-07-13 08:25:21

标签: laravel checkbox

嗨,我有一个问题我有我的问题,例如保存,两个答案正确,但当我参加测试,我点击一个正确,它需要正确。我希望这样做的时候,如果我没有点击两个答案都是正确的,只有当我点击两个以显示正确的答案时才会这样做。

  foreach($answers as $answer){
            $correct_answer = Answer::where('id', $answer)->where('correct', 1)->where('deleted',0)->get();

            if(count($correct_answer) == 1){
                $answer_result = 1;
            }else{
                $answer_result = 0;
            }
            $results[$answer] = $answer_result;
        }
    }else{
        //if test hasn't any answer selected than all answers are wrong 
        $questions = Question::where('test_id', $test_id)->where('deleted',0)->get();

        foreach($questions as $question){
            $answers = Answer::where('question_id', $question->id)->where('deleted',0)->get();
            foreach($answers as $answer){
                $results[] = 0;  
            }
        }
    }

0 个答案:

没有答案