只选择那些不属于特定学生的研讨会


Select only those seminars, that are not attached to a particular student

假设我们定义了Student belongsToMany Seminar关系。如何只选择那些不属于特定学生的研讨会?

这应该可以做到:

$seminars = Seminar::whereDoesntHave('students', function($q) use ($studentId) {
  $q->where('seminar_student.student_id', $studentId);
})->get();