I have strange problem and can't understand from where its came. On my page I have Top Level category
. When I click on top level category is open page with all sub-categories which they have products.
The problem is that if I have 2 products in sub-category_1
I see two times sub-category_1
on the page.
This is the controller which I have
public function showSubCats($categoryId) {
$subcats = SubCategories::select('*', DB::raw('sub_category.sub_cat_id AS sub_cat_id'))
->leftJoin('products', function($join) {
$join->on('products.sub_cat_id', '=', 'sub_category.sub_cat_id');
})
->where('sub_category.category_id', '=', $categoryId)
->whereNotNull('products.sub_cat_id')
->get();
return View::make('site.subcategory', [
'subcats' => $subcats
]);
}
Here is the view
@foreach($subcats as $i => $subcategory)
// html
@endforeach
This is the result.. should be one sub-category with two products inside.. now I have two identical sub-cats.. same products, same id..