Update Column With Multiple Value Using Query Builder and Laravel

  laravel, mysql

I am updating data in a column with many values. Only the last data/ from that column is updated.

View

<input type="text" name="skor[]" class="form-control form-control-sm col-md-5" maxlength="2" autofocus>

Controller

$data = DB::table('test')->get();
        $arr = [];

        for ($i=0; $i < sizeof($data) ; $i++) { 
             $skor = DB::table('test')->where('id_mahasiswa', '=', $request->id_mhs)->update([
                'skor' => $request->skor[$i],
            ]);

             array_push($arr,$skor);
        }

Source: Laravel

Leave a Reply