1

how to add arrays in the controller? how to add an array to enter the database using addrow in laravel?

need his help

javascript addrow

    function formatRows(main, prefer, common,satuanu,kodeu) {
  return '<tr style="text-align: center;"><td class="col-xs-3"><input type="text" value="' +main+ '" id="kode_bmn" name="kode_bmn[]" class="form-control editable" readonly/></td>' +
         '<td class="col-xs-3"><input type="text" value="' +prefer+ '" id="jenis_barang" name="jenis_barang[]"  class="form-control editable" readonly/></td>' +
         '<td class="col-xs-3"><input type="text" value="' +common+ '"id="kuantitas" name="kuantitas[]" class="form-control editable" readonly/></td>' +
         '<td class="col-xs-3"><input type="text" value="' +satuanu+ '"id="satuan_ukuran" name="satuan_ukuran[]" class="form-control editable" readonly/></td>' +
         '<td class="col-xs-3"><input type="text" value="' +kodeu+ '" id="kode_unit" name="kode_unit[]" class="form-control editable" readonly/></td>'+
         '<td class="col-xs-1 text-center"><a href="#" onClick="deleteRow(this)">' +
         '<i class="fa fa-trash" aria-hidden="true"></a></td></tr>';
};

Controller

public function store_pesanan(request $request ,$id){
    if(!Session::get('login')){
        return redirect('/login')->with('alert','Kamu harus login dulu');
    }
    else{
        DB::table('tbl_paket')
        ->where('id_paket',$id)
        ->update(['status_paket' => $request->status_paket]);

        $data = new ModelPesanan();
        $data->id_paket         = $request->get('id_paket');
        $data->kode_bmn         = $request->get('kode_bmn');
        $data->kode_unit        = $request->get('kode_unit');
        $data->jenis_barang     = $request->get('jenis_barang');
        $data->kuantitas        = $request->get('kuantitas');
        $data->satuan_ukuran    = $request->get('satuan_ukuran');
        $data->status_pesanan   = $request->get('status_pesanan');
        $data->save();

        Alert::success('Sukses!', 'Berhasil Menambahkan Pesanan!');
        return redirect ('/daftar_paket');  
    }
}

enter image description here

please help me

1
  • Not sure what you are trying to achive but if you wanna alter a databse with JavaScript you will need to use AJAX. Maybe this might help: stackoverflow.com/questions/49808583/… Commented Mar 8, 2020 at 17:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.