未定义的索引:jawaban

I want to input multiple data to database using array, but I got an error message. The code are in the following bellow :

ClusterController

$jawaban = $request->jawaban;

$data = [];
if($jawaban != null || $jawaban == false){
  for($i=1; $i<=count($jawaban['jawaban']); $i++){
     $data[] = array('jawaban' => $jawaban[$i]['jawaban']);
  }

  $store = Soal::where('cluster_id', $id)->update($data);
  return dd($store);
}

showexam.blade.php

    <form action="/jawaban/store/{{$model[$i]->id}}" method="post" enctype="multipart/form-data"> 
    @csrf
        <table id="datatable" style="width:100%">
        <tbody>           
            <tr>{{$i+1}}. </tr>
            <tr>{{$model[$i]->soal}}</tr>
            <ol type="A" style="">
                <li> {{$model[$i]->A}}</li>
                <li> {{$model[$i]->B}}</li>
                <li> {{$model[$i]->C}}</li>
                <li> {{$model[$i]->D}}</li>
                <li> {{$model[$i]->E}}</li>
            </ol>
            <input list="browsers" name="jawaban[]">
            <datalist id="browsers">
              <option value="A">
              <option value="B">
              <option value="C">
              <option value="D">
              <option value="E">
            </datalist>
        @endfor
            <button type="submit" class="btn btn-primary text-right" id="modal-btn-save">Done</button>
    </form>

screenshot

count($jawaban['jawaban'])

You already have an array called jabawan that you retrieved with $jawaban = $request->jawaban;

That jabawan will have a normal counting array $jabawan = ['A', 'B']

It will not have an index called jabawan.

If you had done something like

$jabawan = post();

You could use your code, but you can just use

for($i=0; $i<count($jawaban); $i++){
   $data[] = array('jawaban' => $jawaban[$i]);
}

Change Soal::where('cluster_id', $id)->update($data);

into

if ($soal_model = Soal::find( $id )) {
   $soal_model->update($data);
}

The problem is that you're never calling get() on the query object, or a first() on the collection that the get() returns.

By using find() You get an object back or null if it doesn't exist. By wrapping that in an if statement the update will only be executed on an existing object, preventing errors on trying to update a null value.

Also, you cannot return a dd().

dd stands for 'dump and die' I believe, at least that is what I read into it because that's what it does.

It dumps the data and then kills the process. So all laravel return handlers won't get called after your dd() call. You killed the process.