I am trying to update student attendance records, but the values are getting incorrectly to the controller.
Form where I send the data to update the attendance record, that is, select checkbox to mark the student as present, or leave the checkbox blank to insert it as absent in the database in the attendance table
public function enviarAsistencia(Request $request, $idCurso){
//estado de la asistencia , es el checkbox 1 presente 2 ausente
$estadoAsistencia = $request->asistencia;
//id de la asistencia del alumno
$asistenciaId = $request->asistenciaId;
foreach($asistenciaId as $index => $id) {
$estado = (isset($estadoAsistencia[$index])) ? 1 : 2;
$asistencia = Asistencia::find($id);
$asistencia->estado = $estado;
$asistencia->save();
}
return back()->with('Listo','Asistencia ingresada correctamente');
}