$(document).ready(function(){$(".alergia-boton").click(function(){
if($("#id_alergia_paciente").val().length <= 1){
return false
}
else{
let valor = $("#id_alergia_paciente").val();
let html = $('#formulario_registro').html();
html+='<input type="text" name="alergia_paciente[]" value="${valor}">';
$('#formulario_registro').html(html);
$('#id_alergia_paciente').val("");
}
});});
I have this script that generates dynamic input and I need to save it in a table that has fields id and allergies_patient, the values of the input would go in allergies_patient but when I save them in the controller with a for, it adds the id nothing else and it leaves me null the allergy_patient field that is to say that you are not collecting the data from the input.
this is the function that stores them in the controller:
DB::beginTransaction();
try{
for($i=0;$i<=1;$i++){
$alergia = new Alergia;
$alergia->paciente_alergia_id = Auth::user()->id;
$alergia->alergia_paciente = $request->input('alergia_paciente['.$i.']');
$alergia->save();
}
}catch(Exception $e){
DB::rollback();
throw $e->getMessage();
return 'ERROR';
}
DB::commit();
Sesion_usuario::Sesion_usuario();
return 'EXITO';
Could you help me see why it does not save the values of the input?