我有这行代码:
$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
我究竟做错了什么?
最佳答案
我通过以下方法解决了我的问题:
$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();
关于mysql - Laravel加入多个条件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53157221/