Php 从子类别页面上的产品阵列中获取所有品牌
在子类别页面上获取产品数组,但是,如何从这样的数组中获取不同的品牌Php 从子类别页面上的产品阵列中获取所有品牌,php,laravel,eloquent,Php,Laravel,Eloquent,在子类别页面上获取产品数组,但是,如何从这样的数组中获取不同的品牌 $product_sub_categories = ProductsSubCategory::where('product_sub_category_slug', $slug)->first(); $products = Products::all()->where('subcategory_id', $product_sub_categories->id); $brands = Brand::all()-&g
$product_sub_categories = ProductsSubCategory::where('product_sub_category_slug', $slug)->first();
$products = Products::all()->where('subcategory_id', $product_sub_categories->id);
$brands = Brand::all()->where('id', $products->brand_id)->distinct(); //help here
在get()
将提高性能之前使用where()
您可以在$products
集合中使用pulk('brand_id')
,以获取品牌识别码
:
$product\u sub\u categories=productssubcategority::where('product\u sub\u categority\u slug',$slug)->first();
$products=products::where('subcategory_id',$product_sub_categories->id)->get();
$brands=Brand::其中('id',$products->pull('Brand_id')->all())->get();
在get()
将提高性能之前使用where()
您可以在$products
集合中使用pulk('brand_id')
,以获取品牌识别码
:
$product\u sub\u categories=productssubcategority::where('product\u sub\u categority\u slug',$slug)->first();
$products=products::where('subcategory_id',$product_sub_categories->id)->get();
$brands=Brand::其中('id',$products->pull('Brand_id')->all())->get();
尝试在->get()
的末尾使用$brands
查询。你建立了品牌和产品之间的关系吗?尝试在->get()
的末尾使用$brands
查询。你建立了品牌和产品之间的关系吗?成功了,谢谢,谢谢