Problem with wherein Eloquent Laravel

Asked

Viewed 363 times

2

I need to execute 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 difficulties with the anonymous 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 WhereIn

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

I don’t know how to do with these whereIn to work.

  • 1

    Amanda instead of "photos" copy and paste the error, it is easier.

  • 1

    Note: I withdrew the closing vote, because the confusion between Where and wherein is not really a "mistake", but goes from the understanding of the framework, what seems to me a valid doubt. BS 2: It wasn’t me who was negative.

  • 1

    I find the doubt valid equal quote @Guilhermenascimento... also I was not the one who negatived.

  • Although I think the question is a typo, I was not the one who denied it as well. In this case, if someone disagrees with the scope of the question, they should use the closing options. Voting is another case.

1 answer

5


You missed that part:

->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 Where clashes enclosed in parentheses, you should always use where with Closure.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.