我想从products
AppServiceProvider
信息
类别 - >子类别 - >产品
现在我需要products
基于类别id
注意:您可能认为这很奇怪,但事实并非如此,只是想象您希望在该类别的所有子类别的类别页面中展示产品。那你就像我一样需要这样的事情。在category_id
中获取产品时,只在产品表中保存subcategory_id
。
这是AppServiceProdiver
中的循环:
View::composer('welcome', function ($view) {
$categories = Category::join('admin_designs', 'admin_designs.category_id', '=', 'categories.id')->get();
foreach($categories as $category){
$subcategory = Subcategory::join('categories', 'categories.id', '=', 'subcategories.category_id')->first();
$designs = Product::where('subcategory_id', $subcategory)->first();
}
$view->with('categories', $categories);
});
该循环的结果是:
{"id":2,"title":null,"slug":"laptop","image":"category-1516430091.jpg","imageAlt":null,"status_id":1,"meta_tags":"laptop,tags","meta_description":"laptop description","created_at":"2018-02-01 11:41:30","updated_at":"2018-02-01 11:41:30","category_id":1},
PS:不知道那是什么!不是产品/不完整
类别less title!
...:|
任何人都可以帮助修复该查询吗?
答案 0 :(得分:0)
View::composer('welcome', function ($view) {
$category = DB::table('admin_designs')
->join('categories', 'categories.id', '=', 'admin_designs.category_id')
->join('subcategories', 'subcategories.category_id', '=', 'categories.id')
->join('products', 'products.subcategory_id', '=', 'subcategories.id')
->get();
$view->with('category', $category);
});
希望它有所帮助。