我有这行代码:
$user['preference'] = PdTpreference::join('pd_tprofessional_preference', 'pd_tprofessional_preference.fkpreference', '=', 'pd_tpreference.pkpreference AND pd_tprofessional_preference.fkprofessional =' . $tmp->pkprofessional, 'left')->get();
但结果如下:
select * from `pd_tpreference` left join `pd_tprofessional_preference` on `pd_tprofessional_preference`.`fkpreference` = `pd_tpreference`.`pkpreference AND pd_tprofessional_preference`.`fkprofessional =12` where `pd_tpreference`.`deleted_at` is null
当我期望它像这样出现时:
select * from `pd_tpreference` left join `pd_tprofessional_preference` on `pd_tprofessional_preference`.`fkpreference` = `pd_tpreference`.`pkpreference` AND `pd_tprofessional_preference`.`fkprofessional` = 12 where `pd_tpreference`.`deleted_at` is null
我在做什么错了?
答案 0 :(得分:0)
我通过以下方法解决了我的问题:
$user['preference'] = PdTpreference::leftJoin('pd_tprofessional_preference', function($q) use ($tmp){ $q->on('pd_tprofessional_preference.fkpreference', '=', 'pd_tpreference.pkpreference')->where('pd_tprofessional_preference.fkprofessional', '=', $tmp->pkprofessional); })->get();