Laravel 我将如何与条件内在地结合在一起,由拉雷维尔雄辩地热切载入

Laravel 我将如何与条件内在地结合在一起,由拉雷维尔雄辩地热切载入,laravel,eloquent,eager-loading,Laravel,Eloquent,Eager Loading,//但第二个代码不是我想解决的内部连接 //我将如何访问主模型中的函数模型特定列——解决此问题->使用whereHas而不是where。您可以使用whereHas方法完成所需操作,该方法将对关系执行查询: enter code here $wo=Warehouse_other_receive_detail::with('item_info','item_info.product_sub_group') ->wher

//但第二个代码不是我想解决的内部连接
//我将如何访问主模型中的函数模型特定列——解决此问题->

使用whereHas而不是where。您可以使用whereHas方法完成所需操作,该方法将对关系执行查询:

    enter code here 
                 $wo=Warehouse_other_receive_detail::with('item_info','item_info.product_sub_group')
                ->where('item_info.product_sub_group->sub_group_id', 2)
                ->get();


                 $wo = Warehouse_other_receive_detail::with(['item_info'=>function( $q){
                $q->getQuery()->has('product_sub_group')->where('sub_group_id', 2);
                     }])
                ->get();

尝试此
->where('item\u info.product\u sub\u group.sub\u group\u id',2)
$wo=Warehouse\u other\u receive\u detail::with('item\u info','item\u info.product\u sub\u group')->where('item\u info.product\u sub\u group.sub id',2)-get();我已经试过了,但是它不起作用。但是我想要获取函数之前的where条件,比如$wo=Warehouse\u other\u receive\u detail::with('item\u info')->where('sub\u group\u id',2)->get();
$wo = Warehouse_other_receive_detail::with('item_info')->whereHas('item_info', function ($query){
    $query->where('sub_group_id',2);
})->get();