Good, I have a table that shows a series of records whose fields are input to be able to update them in the table directly. The code works to the point of having more than one row of values in the table. Surely I have to indicate in each input that it is an array name="field []" and in my controller I have to go through the values to do the update, but I need something else since this does not work for me.
The Controller
public function rcUpdate($id,Request $request){
$updateRcNota = Rc::findOrFail($id);
$updateRcNota->nrefrc=$request->nrefrc_update;
$updateRcNota->part_pres=$request->economica;
$updateRcNota->cantidad=$request->inporte_update_rc;
$updateRcNota->fecha=$request->fecha_update_rc;
$updateRcNota->save();
$message = "Actualizado";
if($request->ajax()){
return response()->json([
'message'=> $message
]);
}
}
The js
$(document).ready(function() {
$('.update_rc').blur(function() {
var row = $(this).parents('tr');
var id = row.data('id');
var r = confirm('Desea modificar el registro ');
var dataString = {
'nrefrc': $('#nrefrc_update').val(),
'part_pres': $('#economica').val(),
'cantidad':$('#importe_update_rc').val(),
'fecha':$('#fecha_update_rc').val()
};
var form = $('#form-rc-update');
var url =form.attr('action').replace(':RC_NOTA_UPDATE' , id);
var data=form.serialize();
if(r==true)
{ $.ajaxSetup({
url:url,
data:data,
type:'post',
dataType: 'json',
headers: {'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')}
});
$.ajax({dataString,
statusCode: {
500: function() {
alert( "Error: entrada duplicada" );
}
},
success: function(result) {
alert(result.message);
}
});
}
});
});