Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在查询生成器laravel中执行此SQL_Sql_Laravel_Query Builder_Laravel Query Builder - Fatal编程技术网

如何在查询生成器laravel中执行此SQL

如何在查询生成器laravel中执行此SQL,sql,laravel,query-builder,laravel-query-builder,Sql,Laravel,Query Builder,Laravel Query Builder,如何在查询生成器laravel中执行此SQL select Doctor_id from doctors where Doctor_id NOT IN (SELECT Doctor_id from report_reviewers WHERE Report_id = 26 ) 试试这个 $result = DB::table('doctors') ->whereNotIn('doctor_id', function($q){ $q->from('report_review

如何在查询生成器laravel中执行此SQL

select Doctor_id from doctors where Doctor_id NOT IN
 (SELECT Doctor_id from report_reviewers WHERE Report_id = 26 )
试试这个

$result = DB::table('doctors')
->whereNotIn('doctor_id', function($q){
    $q->from('report_reviewers')
    ->select('Doctor_id')
    ->where('Report_id', '=', 26)
})
->select('doctor_id')
->get();
当你有疑问的时候,如果你知道原始SQL,你可以简单的做

$query = 'select Doctor_id from doctors ...';
$result = DB::select($query);
而且,所有的功劳都归于这位天才

更新

缺少的参数来自您正在使用的闭包

->whereNotIn('doctor_id', function($q,$id){ 
    $q->from('report_reviewers') 
    ->select('Doctor_id') 
    ->where('Report_id',$id); 
}) 
您需要像这样传递
$id
变量

->whereNotIn('doctor_id', function($q) use ($id) { 
    $q->from('report_reviewers') 
    ->select('Doctor_id') 
    ->where('Report_id',$id); 
}) 

请重试并查看。

这是怎么回事:$result=DB::table('doctors')->join('users','doctors.UserID','=','users.id')->where('doctors.Acceptable',1)->whereNotIn('doctor\u id',function($q,$id){$q->from('report\u reviewers')->选择('doctor\u id'))->where('Report_id',$id);})->select('doctors.doctor_id','users.name')->get();在论点2($id)中丢失了哦,没关系。你忘恩负义。我的密码成功了,你接受了我的答案。现在你需要进一步的帮助,你不接受我的回答,即使它有效。一切都很好,祝你有一个愉快的一天。感谢EddyTheDove帮助我编辑此$this->xx=$id$result=DB::table('doctors')->join('users','doctors.UserID','=','users.id')->where('doctors.Acceptable',1)->whereNotIn('doctors_id',function($q){$q->from('report_reviewers')->select('doctors_id')->where('report_id',$this->xx);)->select('documents.doctor_id','users.name')->get();