DB::connection()->enableQueryLog(); CourseRepository::whereHas('properties', function ($query) { $query->where('user_id', 1); })->with(['properties' => function ($query) { $query->where('user_id', 1); }])->get(); DB::getQueryLog();
得到的执行结果如下所示:
[ [ "query" => "select * from `courses` where exists (select * from `course_properti es` where `courses`.`id` = `course_properties`.`course_id` and `user_id` = ? and `course_properties`.`deleted_at` is null) and `courses`.`deleted_at` is null", "bindings" => [ 1, ], "time" => 6543.86, ], ]