amandajgby's avatar

Upload File in Edit Multiple Data Form

I'm trying to create an edit multiple data form like this (https://i.stack.imgur.com/UOfmf.png) using Laravel 8. In the form, you could upload only one file for each row. I could update the data without uploading file, but when I check the database, the controller updated all of the bukti column value to the same file name. If I tried to update file for two rows, all of the bukti column is just update the value to the last uploaded file name. What I want is there's just one data for jumlah, keterangan, and one bukti file in a row, so I can have different files for each row. This is my code:

Controller: if($request->file('bukti') !=null) { //upload file $bukti=array(); if($files=$request->file('bukti')) { foreach($files as $file) { $name=$file->hashName(); $path=$file->storeAs('blabla',$name); $bukti=$name; } }

//Update multiple data if(count($request->id) > 0) { foreach($request->id as $item => $v) { $data = array( 'id_laporan' => $laporan_indikators->id, 'id_pertanyaan' => $request->id_pertanyaan[$item], 'jumlah' => $request->jumlah[$item], 'keterangan' => $request->keterangan[$item], 'bukti' => $bukti, ); $data_laporans = DataLaporan::where('id',$request->id[$item])->first(); $data_laporans->update($data); } }

I don't really know how to fix this because I'm still a beginner. Thank you for your help.

0 likes
0 replies

Please or to participate in this conversation.