无法存储带有输入的控制器的关联数组

时间:2019-05-23 07:28:02

标签: php laravel

我想将单选按钮输入保存为数组,当我提交单选按钮时,它无误地转到空白空间,但未保存到数据库中。如何处理这些问题?谢谢

这是我的控制器代码:

public function store(Request $request)
{
    $data_hasilquiz = new HasilQuiz();
    $data_quiz = new Quiz();
    foreach(Input::get('jawaban') as $key => $value) {
        $arr_jawaban = array(str_split($value)); 

        // print_r($arr_jawaban);

        if (array_key_exists($key, $arr_jawaban)) {
            $data_hasilquiz = HasilQuiz::find($key);
            $data_hasilquiz->jawaban = $value;
            $data_hasilquiz->save();
        }
    }
}

和我的观点:

{{Form::open(array('route' => 'QuizView.store'))}}
    {{csrf_field()}}
    @foreach ($data_quiz as $items)
        {{$items->id_quiz}}.{{$items->pertanyaan}}<br> 

        {{Form::radio('jawaban['.$items->id_quiz.']','a')}}{{$items->opsi1}}<br>
        {{Form::radio('jawaban['.$items->id_quiz.']','b')}}{{$items->opsi2}}<br>
        {{Form::radio('jawaban['.$items->id_quiz.']','c')}}{{$items->opsi3}}<br>
    @endforeach
    {{Form::submit('Submit',array('class' => 'btn btn-danger col-md-12'))}}
{{ Form::close() }}

当我print_r($arr_jawabanarr[0] => a, arr[1] => b

0 个答案:

没有答案