I have 3 tables:
Student (id)
Course (id, name)
Enrollment (id, student_id, course_id)
When I login with a student in his account I receive his data with:
$alumno = Alumno::find(auth('alumno')->user()->id);
I tried to get to the registration with:
$matricula = Matricula::where('id_alumno',auth('alumno')->user()->id)->get();
In the enrollment model I already have the relationship for course but doing this:
$matricula->curso;
But the relationship does not work, How can I get the name of the student's course by means of the registration?
Registration Model:
public function curso()
{
return $this->belongsTo(Curso::class,'id_curso','id');
}
public function alumno()
{
return $this->belongsTo(Alumno::class,'id_alumno','id');
}
Course Model:
public function matriculas()
{
return $this->hasMany('App\Matricula','id_curso');
}
Student Model
public function matriculas()
{
return $this->hasMany('App\Matricula','id_alumno');
}