0
어디 까지나 NotExists를 이해하면 전달 된 Closure 내의 모든 쿼리가 제외되어야합니다. 그러나 예상치 못한 결과가 나타납니다.Laravel whereNotExists 제대로 작동하지 않습니다.
내가하려는 것은 폐쇄 조건에 적용되는 모든 학생을 돌려 보내는 것입니다. 학부모가 결석 또는 결석 한 학생은 아닙니다. 내가 얻는 것은 빈 학생 배열 []이다.
내가 뭘 잘못하고 있니?
$students = DB::table('rounds')
->where('rounds.bus_id', '=', $bus_id)
->join('rounds_students', 'rounds_students.round_id', 'rounds.id')
->whereNotExists(function ($query) {
$query->select(DB::raw(1))
->from('student_history')
->where('student_history.student_id', '=', 'rounds_students.student_id')
->where('student_history.activity_type', '=', 'absent')
->orWhere('student_history.activity_type', '=', 'absent-by-parent');
})
->join('students', 'students.id', 'rounds_students.student_id')
->select('students.name')
->get();
return $students;
보십시오. 여기에서는 전혀 그렇게하지 않습니다. – apokryfos
@apokryfos 이미 그랬지만 질문에서 언급하는 것을 잊어 버렸습니다. 질문을 업데이트했습니다. 나는 여전히 빈 $ students 배열을 가지고있다. – WingsOfAltair