代替当前查询,尝试是否满足您的需求。(我根据您的评论修改了我的答案)
$parentLineCategories = ProductCategory::with([ 'children' => function ($child) use ($SpecificID) { return $child->with([ 'products' => function ($product) use ($SpecificID) { return $product->with([ 'types' => function ($type) use ($SpecificID) { return $type->where('id', $SpecificID); } ]); } ]); } ])->get();