Laravel 7.x Laravel生成具有雄辩能力的子查询

Laravel 7.x Laravel生成具有雄辩能力的子查询,laravel-7.x,Laravel 7.x,我想生成如下所示的SQL查询: select * from ocs where ocs.wfx_oc_no = 'OC11' and ocs.id in (select id from buyers where buyers.buyer_code = 'B01') 有人能帮助我如何处理laravel子查询吗?$data=OCS::where('wfc_oc_no','OC11')->where('id',buyer::where('buyer_code'

我想生成如下所示的SQL查询:

select *
from ocs
where ocs.wfx_oc_no = 'OC11' and
ocs.id in (select id
          from buyers
          where buyers.buyer_code = 'B01')

有人能帮助我如何处理laravel子查询吗?

$data=OCS::where('wfc_oc_no','OC11')->where('id',buyer::where('buyer_code','B01')->first())->get()

这将进行多个DB调用,而子查询只执行一次。在我的例子中,有很多where子句。这不是我所期望的答案。不管怎样,它让我了解了我现在在做什么。谢谢你的输入。这可以用来完成工作,所以我把它作为答案。无论如何,我期待一些基于子查询的东西。谢谢,下次我会尝试给出最好的答案