I created a table in order to show the name of the students, name of the subjects and the grade of the subject of the student I have the next code: this is the index part
<form action="{{ route( Formatos.index ) }}" method="GET">
<select name="carrera_id">
<option value="">Seleccione una carrera</option>
@foreach ($carreras as $carrera)
<option value="{{ $carrera->IdCarreras }}">{{ $carrera->NombreCarrera}}</option>
@endforeach
</select>
<select name="Semestre_id">
<option value="">Seleccione un semestre</option>
@foreach ($semestres as $semestre)
<option value="{{ $semestre->IdSemestres }}">{{ $semestre->Semestre}}</option>
@endforeach
</select>
<select name="turno">
<option value="">Seleccione un turno</option>
<option value="Matutino">Matutino</option>
<option value="Vespertino">Vespertino</option>
</select>
<select name="salon">
<option value="">Seleccione un salon</option>
<option value="Salon A">Salon A</option>
<option value="Salon B">Salon B</option>
<option value="Salon C">Salon C</option>
<option value="Salon D">Salon D</option>
<option value="Salon E">Salon E</option>
<option value="Salon F">Salon F</option>
<option value="Salon G">Salon G</option>
<option value="Salon H">Salon H</option>
</select>
<select name="U1">
<option value="U1">Seleccione una unidad</option>
<option value="U1">U1</option>
<option value="U2">U2</option>
<option value="U3">U3</option>
<option value="U4">U4</option>
<option value="U5">U5</option>
</select>
<button type="submit">Mostrar</button>
</form>
@csrf
<table id="tabla_datos" class="table table-striped mt-2">
<thead style="background-color:#6777ef">
<tr>
<td rowspan="2" > ```
``@if ($materias->count() > 0)
<table style=" width: 1180px;">
<thead>
<tr style=" width: 110px;">
<td style="background-color: gray; color:#fff; width: 80px;"> Asignatura</td>
@foreach ($materias as $materia)
<th style="background-color: #18316B; color:#fff; width: 90px;">{{ $materia->NombreMateria }}</th>
@endforeach
<th style="background-color: #18316B; color:#fff;width: 80px;" colspan="6">Observaciones</th>
</tr>
</thead>
<thead>
<tr>
<td style="background-color: gray; color:#fff;"> Unidades</td>
<td style="background-color: #18316B; color:#fff;">
<select id = "grade-selector" class="form-control" style="width: 80px;">
<option value="U1">U1</option>
<option value="U2">U2</option>
<option value="U3">U3</option>
<option value="U4">U4</option>
<option value="U5">U5</option>
</select>
</td>
<td style="background-color: #18316B; color:#fff;">
<select id = "grade-selector2" class=" form-control" style="width: 80px;" >
<option value="U1">U1</option>
<option value="U2">U2</option>
<option value="U3">U3</option>
<option value="U4">U4</option>
<option value="U5">U5</option>
</select>
</td>
<td style="background-color: #18316B; color:#fff;">
<select id="grade-selector3" class=" form-control" style="width: 80px;">
<option value="U1">U1</option>
<option value="U2">U2</option>
<option value="U3">U3</option>
<option value="U4">U4</option>
<option value="U5">U5</option>
</select>
</td>
<td style="background-color: #18316B; color:#fff;">
<select id = "grade-selector4" class=" form-control" style="width: 80px;">
<option value="U1">U1</option>
<option value="U2">U2</option>
<option value="U3">U3</option>
<option value="U4">U4</option>
<option value="U5">U5</option>
</select>
</td>
<td style="background-color: #18316B; color:#fff;">
<select id = "grade-selector5" class=" form-control" style="width: 80px;">
<option value="U1">U1</option>
<option value="U2">U2</option>
<option value="U3">U3</option>
<option value="U4">U4</option>
<option value="U5">U5</option>
</select>
</td>
<td style="background-color: #18316B; color:#fff;">
<select id = "grade-selector6" class=" form-control" style="width: 80px;">
<option value="U1">U1</option>
<option value="U2">U2</option>
<option value="U3">U3</option>
<option value="U4">U4</option>
<option value="U5">U5</option>
</select>
</td>
<td style="background-color: #18316B; color:#fff; width: 1000px;"> </td>
</tr>
@endif
@if ($alumnos->count() > 0)
<table>
<tbody>
@foreach ($alumnos as $index => $alumno)
@if (isset($estudiantes[$index]) && isset($calificaciones[$index]))
<tr>
<td style="background-color: #fff; color:black; width: 110px; text-align: center;"> {{ $estudiantes[$index]->name }}</td>
@foreach ($calificaciones as $calificacion)
<td class="grade-cell U1" style="background-color: #fff; color:black; width: 180px; text-align: center;">{{ $calificacion->U1 }}</td>
@endforeach
@foreach ($calificaciones as $calificacion)
<td class="grade-cell2 U2" style="background-color: #fff; color:black; width: 180px; text-align: center;">{{ $calificacion->U2 }}</td>
@endforeach
@foreach ($calificaciones as $calificacion)
<td class="grade-cell U3" style="background-color: #fff; color:black; width: 180px; text-align: center;">{{ $calificacion->U3 }}</td>
@endforeach
<td style="background-color: #fff; color:black; width: 130px;">
<textarea id="observaciones-{{ $index }}" name="observaciones[]" rows="3" cols="25">{{ $formatos[$alumno->Alumno_id]->observaciones ?? }}</textarea>
<button onclick="guardarComentarios({{ $alumno->Alumno_id }})">Guardar</button>
</td>
</tr>
@endif
@endforeach
</tbody>
</table>
@endif
@section( scripts )
<script>
function printTable()
{
var table = document.getElementById("tabla_datos");
var printWindow = document.createElement( iframe );
printWindow.style.position = absolute ;
printWindow.style.top = -10000px ;
printWindow.style.left = -10000px ;
document.body.appendChild(printWindow);
printWindow.contentDocument.write( <html><head><title>Imprimir tabla</title> );
printWindow.contentDocument.write( </head><body> );
printWindow.contentDocument.write(table.outerHTML);
printWindow.contentDocument.write( </body></html> );
printWindow.contentWindow.print();
setTimeout(function ()
{
document.body.removeChild(printWindow);
}, 1000);
}
function guardarComentarios(alumnoId) {
var comentarios = document.getElementById( comentarios_ + alumnoId).value;
// Realiza una petición AJAX para guardar los comentarios en el backend
// Puedes utilizar jQuery o la librería nativa fetch() para realizar la petición
// Ejemplo con jQuery:
$.ajax({
method: POST ,
url: /Formatos/agregarComentarios ,
data: {
alumno_id: alumnoId,
comentarios: comentarios
},
success: function(response) {
alert( Comentarios guardados exitosamente );
},
error: function(error) {
alert( Error al guardar los comentarios );
}
});
}
$( #grade-selector ).on( change , function() {
var selectedGrade = $(this).val();
// Hide all grade cells
$( .grade-cell ).hide();
$( .grade-cell2 ).hide();
// Show the selected grade cell
$( . + selectedGrade).show();
});
$( #grade-selector ).trigger( change );
</script>
@endsection
this is the controller of Calificacion. I have created the index function in order to show the name of the student and of the subject, and the grade of the student and subject. In the index view, I created drop down list where I can choose the career, semester, classroom and schedule, and inside the table I created six drop down list where it shows the name of the subject
class FormatoController extends Controller
{
// $data = Process::with( user )->findOrFail(Auth::id());
/**
* Display a listing of the resource.
*
* @return IlluminateHttpResponse
*/
public function index(Request $request)
{
$query = Calificacion::select( Alumno_id )->get();
$carreras = Carrera::all();
$comentarios = Formato::all();
$calificaciones = Calificacion::all();
$maestros = Maestro::all();
$turnos = Calificacion::all();
$salones = Calificacion::all();
$semestres = Semestre::all();
$estudiantes = Calificacion::join( users , users.id , = , calificacions.Alumno_id )
->select( users.name )
->distinct()
->get();
// Obtener la lista de alumnos distintos
$alumnos = Calificacion::select( Alumno_id )->distinct()->get();
// Obtener la lista de materias relacionadas con las calificaciones
$calificaciones = Calificacion::first();
$calificaciones = Calificacion::with( materias , calificaciones )->get();
$calificaciones = Calificacion::select( Alumno_id , U1 , Materia_id , U2 , U3 , U4 , U5 , U6 , U7 , U8 , U9 , U10 , U11 , U12 )->distinct()->get();
// Obtener los formatos relacionados con los alumnos
$formatos = Formato::whereIn( nombre , $alumnos->pluck( Alumno_id ))->get()->keyBy( Alumno_id );
// Obtener los filtros de búsqued
$semestreId = $request->input( Semestre_id );
$maestroId = $request-> input( Maestro_id );
$materiaId = $request -> input( Materia_id );
$turnoId = $request -> input( turno );
$salonId = $request -> input( salon );
$calificacionId = $request->input( U1 );
$calificacionId = $request->input( U2 );
$calificacionId = $request->input( U3 );
$calificacionId = $request->input( U4 );
$calificacionId = $request->input( U5 );
$calificacionId = $request->input( U6 );
$calificacionId = $request->input( U7 );
$calificacionId = $request->input( U8 );
$calificacionId = $request->input( U9 );
$calificacionId = $request->input( U10 );
$calificacionId = $request->input( U11 );
$calificacionId = $request->input( U12 );
// Filtrar por carrera seleccionada
if (request()->has( carrera_id )) {
$carreraId = request( carrera_id );
$alumnos = Calificacion::where( Carrera_id , $carreraId)->get(); // Obtener los alumnos de la carrera seleccionada
$materias = Materia::where( carrera_id , $carreraId)->get(); // Obtener las materias de la carrera seleccionada
if ($semestreId) {
$materias = $materias->where( semestre_id , $semestreId);
}
if ($calificacionId) {
$calificaciones = $calificaciones->where( U1 , U2 , U3 , U4 , U5 , U6 , U7 , U8 , U9 , U10 , U11 , U12 , $calificacionId);
$calificaciones= Calificacion::where( Materia_id , $calificacionId)
->where( U1 , $calificacionId)
->get();
foreach ($calificaciones as $calificacion) {
$calificacion->U1;
$calificacion->U2;
$calificacion->U3;
$calificacion->U4;
$calificacion->U5;
}
$materias= Calificacion::where( Materia_id , $calificacionId)
->where( U1 , $calificacionId)
->get();
$materias = $materias->where( U1 , U2 , U3 , U4 , U5 , U6 , U7 , U8 , U9 , U10 , U11 , U12 , $calificacionId);
$alumnos = $alumnos->where( U1 , U2 , U3 , U4 , U5 , U6 , U7 , U8 , U9 , U10 , U11 , U12 , $calificacionId);
}
if ($turnoId) {
$semestres = $semestres->where( turno , $turnoId);
$materias = $materias->where( turno , $turnoId);
$alumnos = $alumnos->where( turno , $turnoId);
$alumnos= Calificacion::where( turno , $turnoId)
->get();
$semestres= Calificacion::where( turno , $turnoId)
->get();
$materias= Calificacion::where( turno , $turnoId)
->get();
}
if ($salonId) {
$semestres = $semestres->where( salon , $salonId);
$alumnos= Calificacion::where( salon , $salonId)
->get();
$semestres= Calificacion::where( salon , $salonId)
->get();
$materias= Calificacion::where( salon , $salonId)
->get();
$materias = $materias->where( salon , $salonId);
$alumnos = $alumnos->where( salon , $salonId);
}
if ($maestroId)
{
$maestros = $maestros->where( Maestro_id , $maestroId);
}
} else {
$alumnos = collect(); // Crear una colección vacía de alumnos
$materias = collect(); // Crear una colección vacía de materias
$semestres = collect();
$calificaciones = collect();// Crear una colección vacía de calificaciones
$maestros = collect();
$calificacionesPorUnidad = [];
}
$calificaciones = Calificacion::with( materias )->get();
$calificaciones->each(function ($calificacion) {
$alumno = optional(Calificacion::find($calificacion->Alumno_id));
$calificacion->alummos = $alumno->Alumno_id ?? null;
$calificacion->materias = optional(Materia::find($calificacion->Materia_id))->NombreMateria;
});
// Filter calificaciones by selected units
$formatos = Formato::paginate(10);
return view( Formatos.index ,compact( carreras , alumnos , materias , formatos , estudiantes , semestres , calificaciones , maestros , turnos , salones ));
}
Route
Route::get( /Formatos ,[ FormatoController::class, index ])->name( Formatos.index );
When I choose for example U1, it only works on one drop down list and only shows like this
When I have this in the database in phpmyadmin
So I don t know what to change or correct