Clauses wherein and whereNotIn

Asked

Viewed 65 times

0

I have two tables, one has the disciplines and the other has the periodo_disciplines, I filter the course and the period. I need to bring only the disciplines that are not launched in the table of periodo_disciplines, so the user can add these disciplines that are not launched, could explain to me how the wherein and the whereNotIn of the Laravel works because I can not make it work, in time he bring me 5 which is correct he brings me only 3.

Follows code

inserir a descrição da imagem aqui

Periodo_disciplines:

inserir a descrição da imagem aqui

Disciplines:

inserir a descrição da imagem aqui

Periodos Letivos:

inserir a descrição da imagem aqui

  • Please put code and not image, the part of the tables is fine, but, the part of code put the text and use the formatting tool

1 answer

0


The wherein and the whereInNot in the first parameter the field name and in the second parameter the array simples, example [1,2,3].

In your code you need an adjustment because the get returns a complex data, that is, different than the wherein/whereInNot accurate, use the method Pluck and in the end the method toArray(), example:

$disciplinas_id_in_periodos = PeriodoDisciplina::
      where('periodo_letivos_id', '=', $periodo_letivo->id)
      ->select('disciplina_id')
      ->pluck('disciplina_id')
      ->toArray();

$disciplinas = Disciplina::where('id','like','%%')
     ->where('cursos_id','=',$cursos_id)
     ->select('id')
     ->pluck('id')
     ->toArray();

now the two variables ($disciplinas_id_in_periodos and $disciplinas) sane array simples and it will work what you need.

References

Browser other questions tagged

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