I would like to search all the people of a given class based on the class code using Laravel:
And soon after page, to make a list.
Student
public function turmas()
{
return $this->belongsToMany(Turma::class,'turma_classe', 'turma_id','aluno_id');
}
Class
public function alunos()
{
return $this->belongsToMany(Aluno::class,'turma_classe', 'aluno_id','turma_id');
}
Search
$aluno = Aluno::find(1);
$turmas = $aluno->turmas;
foreach($turmas as $turma)
{
var_dump(Aluno::with(Turma::class)->where('codigo', $turma->codigo));
}