【发布时间】:2020-02-11 15:04:32
【问题描述】:
我正在尝试使用 Laravel 查询生成器来连接 2 个表。
这是我加入 2 个表的查询
$instructors = DB::table('instructors')
->join('instructor_courses', 'instructors.id', '=','instructor_courses.instructor_id')
->where('instructor_courses.course_id', $schedule->course_id)
->where('instructor_courses.position', 'Instructor')
->whereNull('instructor_courses.deleted_at')
->whereNull('instructors.deleted_at')
->get();
代码让我可以正确加入表格,但这会导致多次重复。看看select标签传入的结果
这是我的架构
基本上我想要实现的是显示一条不重复的记录。有没有更好的方法来加入像这样的多个表?谢谢
【问题讨论】: