如果在另一个相关表laravel查询构建器中不存在记录,则如何从表中获取记录

时间:2018-04-25 07:39:26

标签: laravel query-builder

我有两张桌子

tb_teachers
-----------
id
name
school_id

tb_class_to_teachers
--------------------
id
teacher_id
class_id
assigned_status
school_id

如果使用laravel查询构建器在另一个相关表tb_class_to_teachers中不存在(teacher_id和school_id),则如何从tb_teachers获取记录

2 个答案:

答案 0 :(得分:0)

我假设您正确设置了您的关系,然后您可以使用auto size(const TCollection& c) { return c.GetSize(); }

doesntHave

答案 1 :(得分:0)

试试这个

$classToTeachers = DB::table('tb_class_to_teachers')->get();
        if($classToTeachers->teacher_id == null && $classToTeachers->school_id == null)
        {
            $teacher = DB::table('tb_teachers')->get();
        }