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.