0
I am trying to do this function with Laravel Query Builder
public function getEstudantesCargaHoraria(Request $request)
{
    $ano_letivo = $request->ano_letivo;
    $turma_id  = $request->id;
    $ano_letivo = 2017;
    $turma_id   = 528;
    $estudantes = DB::table('turmas_has_estudantes')
        ->leftJoin('estudantes_identificacao', 'estudantes_identificacao.id', '=', 'turmas_has_estudantes.estudantes_identificacao_id')
        ->leftJoin('estudantes_carga_horaria', function ($join) {
            $join->on('estudantes_carga_horaria.estudantes_identificacao_id', '=', 'turmas_has_estudantes.estudantes_identificacao_id')
                ->where(function ($query)  use ($ano_letivo) {
                    $query
                    ->whereNull('estudantes_carga_horaria.ano_letivo')
                    ->orWhere('estudantes_carga_horaria.ano_letivo', '=', $ano_letivo);
                });
        })
        ->select(
            'turmas_has_estudantes.id AS turmas_has_estudantes_id',
            'turmas_has_estudantes.numero',
            'estudantes_identificacao.nome_completo',
            'estudantes_carga_horaria.id AS estudantes_carga_horaria_id', 
            'estudantes_carga_horaria.estudantes_identificacao_id',
            'estudantes_carga_horaria.ano_letivo',
        )
        ->where('turmas_has_estudantes.turmas_id',     $turma_id)
        ->orderBy('turmas_has_estudantes.numero')
        ->orderBy('estudantes_identificacao.nome_completo')
        ->get();
    return $estudantes;
}
Error message appears: Undefined variable: ano_school
I searched on the Internet and recommended putting: use ($ano_letivo) but, it did not work. Still not recognizing the variable
What a strange thing!! rsrs It worked perfectly! Very Obrgado!!
– Luis Souza