I have a driver that sends a list of enrollments by subject, each registration belongs to a student.
public function showCalificacionesAsignatura($id)
{
$asignatura = Asignatura::find($id);
$matriculados = $asignatura->matriculas;
At the hearing I receive the registration and use your relationship with the student to show their data:
@foreach ($matriculados as $m)
<tr>
<td>{{$m->alumno->apellido_paterno." ".$m->alumno->apellido_materno." ".$m->alumno->nombre}}</td>
How can I sort these student names with orderBy ('parental_name', 'DESC')?
Student Model
public function matriculas()
{
return $this->hasMany('App\Matricula','id_alumno');
}
Registration Model
public function alumno()
{
return $this->belongsTo(Alumno::class,'id_alumno','id')->orderBy('apellido_paterno','DESC');
}
public function curso()
{
return $this->belongsTo(Curso::class,'id_curso','id');
}
public function notas()
{
return $this->hasMany('App\Nota','id_matricula');
}
public function asignaturas()
{
return $this->belongsToMany('App\Asignatura')->orderBy('nombre','ASC');
}
Subject Model
public function matriculas()
{
return $this->belongsToMany('App\Matricula')->withTimestamps();
}