Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从子类别页面上的产品阵列中获取所有品牌_Php_Laravel_Eloquent - Fatal编程技术网

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
查询。你建立了品牌和产品之间的关系吗?成功了,谢谢,谢谢