标签: php laravel laravel-5 eloquent laravel-5.2
假设我们定义了Student belongsToMany Seminar关系。如何只选择那些没有附加到特定学生的研讨会?
Student
belongsToMany
Seminar
答案 0 :(得分:1)
这应该可以解决问题:
$seminars = Seminar::whereDoesntHave('students', function($q) use ($studentId) { $q->where('seminar_student.student_id', $studentId); })->get();