任何人都可以帮我翻译成Eloquent吗?
select * from resources
left join links
on links.resource_id = resources.id
and (links.ud_id IS NULL OR links.ud_id = '7')
where resources.user_id = '1'
and resources.subject_id = '4'
提前谢谢
答案 0 :(得分:1)
这应该可以解决问题:
DB::table('resources')
->leftJoin('links', function($join) {
$join->on('links.resource_id', '=', 'resources.id');
$join->where(function($query) {
$query->whereNull('links.ud_id');
$query->orWhere('links.ud_id', '=', 7);
});
})
->where('user_id', 1)
->where('subject_id', 4)
->get();