2017-04-30 10 views

답변

1

$result = DB::table('doctors') 
->whereNotIn('doctor_id', function($q){ 
    $q->from('report_reviewers') 
    ->select('Doctor_id') 
    ->where('Report_id', '=', 26) 
}) 
->select('doctor_id') 
->get(); 

Whenver 의심과 시도 , 당신은 단순히 또한

$query = 'select Doctor_id from doctors ...'; 
$result = DB::select($query); 

을 할 수있는 모든 신용이 천재 How to create a subquery using Laravel Eloquent?

로 이동 당신이

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

당신은 다시 시도하고 볼이

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

처럼 $id 변수를 전달해야 사용

업데이트

누락 된 인수는 폐쇄에서 비롯됩니다.

+0

효과가 있습니다. 감사! –

+0

어떨까요 : $ result = DB :: table ('의사') -> ('사용자', '의사'사용자 ID ','= ','users.id ') -> ('report_reviewers') -> select ('Doctor_id') -> 여기서 '(') '(허용되는') 1, -> 여기서 ' ('doctors.doctor_id', '사용자 이름') -> get(); 인수 2 ($ id)에 누락되었습니다 –

+0

시도해 보셨습니까? 오류는 무엇입니까? – EddyTheDove