whereIn and whereNotIn clauses

0

I have two tables, one I have the disciplines and the other I have the period_disciplines, filter effect in the course and period. I need to bring only the disciplines that are not released in the table of period_disciplines, so that the user can add these disciplines that are not released, could they explain to me how doesIn and whereNotIn of laravel works because I can not make it work, instead of it bringing me 5 which is correct it brings me just 3.

Follow the code

Period_disciplines:

Disciplines:

AcademicPeriods:

    
asked by anonymous 26.05.2018 / 15:27

1 answer

0

whereIn and the # needs in the first parameter the name of the field and in the second parameter the array simples , example [1,2,3] .

In your code you need an adjustment because get returns a complex data, that is, different than whereIn need >, use the pluck method and at the end the 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 ) are array simples and will work what you need.

26.05.2018 / 17:21