How to do a Left Outer join with Laravel?

后端 未结 1 1315
滥情空心
滥情空心 2020-12-14 15:19

i want information from one table and if there is matched info from another table that as well.

this my code

 $scoreObject = DB::table(\'responses\')         


        
相关标签:
1条回答
  • 2020-12-14 15:59

    You could try specifying the join as being a left outer join:

    ->join('answers as answers', 'responses.answer_id', '=', 'answers.id', 'left outer')
    

    The fourth parameter of the join method is $type, which when not specified, defaults to the value inner. But since left join and left outer join are the same thing, you could just use the leftJoin method instead, to make it more readable:

    ->leftJoin('answers as answers', 'responses.answer_id', '=', 'answers.id')
    
    0 讨论(0)
提交回复
热议问题