Laravel嵌套渴望在主关系中的where条件中加载特定的列

时间:2019-12-25 13:23:15

标签: laravel eloquent eager-loading eager

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

如何在关系中选择条件后的特定列?

1 个答案:

答案 0 :(得分:0)

您可以使用from pathlib import Path Path('test/blah/foo/bar/').mkdir(parents=True, exist_ok=True)

来建立关系
with()

如果您只希望拥有$wo = Warehouse_other_receive_detail::with(['item_info.product_sub_group' => function($productSubGroup) { $productSubGroup->where('sub_group_id', '=', 2); }]) ->get(); 的{​​{1}}使用Warehouse_other_receive_detail

product_sub_group->sub_group_id = 2