Problem with wherein Eloquent Laravel

2

I need to run a query with the parameters as below:

$questoes = Questao::leftJoin('capitulos_questoes', 'capitulos_questoes.questoes_id', '=', 'questoes.id')
            ->leftJoin('modulos_questoes', 'modulos_questoes.questoes_id', '=', 'questoes.id')
            ->leftJoin('banco_disciplinas', function($join){
                $join->on('banco_disciplinas.id', '=', 'capitulos_questoes.banco_disciplinas_id')
                    ->orOn('banco_disciplinas.id', '=', 'modulos_questoes.banco_disciplinas_id');
            })
            ->leftJoin('banco_series', function($join){
                $join->on('banco_series.id', '=', 'capitulos_questoes.banco_series_id')
                    ->orOn('banco_series.id', '=', 'modulos_questoes.banco_series_id');
            })
            ->whereIn('avaliada', $status)
            ->whereIn('tipo', $tipo)
            ->whereIn(function ($query) use ($serie){
                $query->whereIn('modulos_questoes.banco_series_id',$serie)
                    ->orWhereIn('capitulos_questoes.banco_series_id', $serie);
            })
            ->whereIn(function ($query)use ($disciplina){
                $query->whereIn('modulos_questoes.banco_disciplinas_id', $disciplina)
                    ->orWhereIn('capitulos_questoes.banco_disciplinas_id', $disciplina);
            })
            ->select('questoes.id as id', 'questao', 'serie', 'ensino', 'avaliada', 'disciplina', \DB::raw('DATE_FORMAT(questoes.created_at, "%d/%m/%Y") as data'))
            ->paginate($pag);

I'm having trouble with the anonymous function in whereIn . If I take the part below, the query works:

->whereIn(function ($query) use ($serie){
                $query->whereIn('modulos_questoes.banco_series_id',$serie)
                    ->orWhereIn('capitulos_questoes.banco_series_id', $serie);
            })
            ->whereIn(function ($query)use ($disciplina){
                $query->whereIn('modulos_questoes.banco_disciplinas_id', $disciplina)
                    ->orWhereIn('capitulos_questoes.banco_disciplinas_id', $disciplina);
            })

The query is returning this error:

  

Missing argument 2 for Illuminate\Database\Query\Builder::WhereIn()

I do not know how to do with these whereIn to work.

    
asked by anonymous 24.11.2016 / 14:40

1 answer

5

You missed this section:

->whereIn(function ($query) use ($disciplina){
    $query->whereIn('modulos_questoes.banco_disciplinas_id', $disciplina)
        ->orWhereIn('capitulos_questoes.banco_disciplinas_id', $disciplina);
})

Should be:

->where(function ($query) use ($disciplina){
    $query->whereIn('modulos_questoes.banco_disciplinas_id', $disciplina)
        ->orWhereIn('capitulos_questoes.banco_disciplinas_id', $disciplina);
})

To add clause enclosed clauses in parentheses, you should always use where with Closure .

    
24.11.2016 / 14:52