在Laravel中加载子类别时,查询结果加倍

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.. enter image description here

Change your query as

$subcats = DB::table('sub_category as sc')
    ->leftJoin('products as p', 'p.sub_cat_id', '=', 'sc.sub_cat_id')//cross check this sc.sub_cat_id may be it si sc.id
    ->where('sc.category_id', '=', $categoryId)
    ->whereNotNull('p.sub_cat_id')
    ->select('*', DB::raw('sc.sub_cat_id AS sub_cat_id'))
    ->get();