Level 104
Student::has('enrollments')
->whereNotIn(
'id',
Enrollment::select('student_id')->distinct()->whereNotNull('batch_id')
)
->get();
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi guys,
SELECT *
FROM students
WHERE
EXISTS (SELECT * FROM enrollments AS EN WHERE EN.student_id=students.id)
and
students.id NOT IN (
SELECT DISTINCT student_id FROM enrollments where batch_id IS NOT NULL
);
How can we convert this into eloquent
Student::has('enrollments')
->whereNotIn(
'id',
Enrollment::select('student_id')->distinct()->whereNotNull('batch_id')
)
->get();
Please or to participate in this conversation.