如何与Laravel一起加入左外线?
我想要一个表的信息,如果有来自另一个表的匹配信息,那也是。
这是我的代码
$scoreObject = DB::table('responses')
->select('responses.id', 'responses.questions_id', 'responses.answer_id', 'responses.open_answer', 'responses.user_id', 'responses.scan_id',
'questions.question', 'questions.question_nr', 'questions.type', 'questions.totalsection_id',
'answers.id as answerID', 'answers.answer', 'answers.questions_id', 'answers.points'
)
->Join('answers as answers', 'responses.answer_id', '=', 'answers.id')
->Join('questions as questions', 'answers.questions_id', '=', 'questions.id')
->orderBy('questions.id', 'ASC')
->where('responses.scan_id', $scanid)
->where('responses.user_id', $userid)
->groupBy('questions.id')
->get();
它返回与答案匹配的所有响应(answers.questions_id questions.id”)。有些回复不匹配(因为没有responses.answer_id),但我仍然想要回复信息。
我怎么能在拉拉维尔得到这样一个左外加入?