title: Laravel : How to show dependent variable on tab
body: <p>I have two tables , categories and product.Each category has id and name. Each product has id, name and category id. Now I want to load the data on each tab when a user click on specific category_id.so related product will be shown on each category tab. I have tried but couldn't get the solution.</p>
  
  <p>Category Model:</p>
  
  <pre><code>class Category extends Model
  {
      public function products()
  
      {
          return $this-&gt;hasMany('App\Product');
      }
  }
  </code></pre>
  
  <p>Product Model:</p>
  
  <pre><code>class Product extends Model
  {
       public function category()
           {
               return $this-&gt;belongsTo('App\Category');
           }
  
  }
  </code></pre>
  
  <p>Here is my controllers:</p>
  
  <pre><code>public function gettestItem() {
                  $categories = Category::with('products')-&gt;get();
                  return view('products', compact('categories'));
              }
  </code></pre>
  
  <p>Here is the view :</p>
  
  <pre><code>&lt;div class="container"&gt;
          &lt;div id="content"&gt;               
            &lt;ul id="tabs" class="nav nav-tabs" data-tabs="tabs"&gt;   
               @foreach ($categories as $category)              
                  &lt;li&gt;&lt;a href="#{{$category-&gt;id}}" data-toggle="tab" &gt;{{$category-&gt;name}}&lt;/a&gt;&lt;/li&gt;
               @endforeach
            &lt;/ul&gt;
  
               &lt;div id="my-tab-content" class="tab-content"&gt;
                  @foreach($categories as $category)
                    @foreach($category-&gt;products as $product) 
                    &lt;div class="tab-pane " id="{{$category-&gt;id}}"&gt;
                        {{$product-&gt;name}}
                    &lt;/div&gt;  
                    @endforeach
                  @endforeach
              &lt;/div&gt;     
          &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>Here is the route:</p>
  
  <pre><code>Route::get('/testItem',[
  'uses'=&gt;'ItemController@gettestItem',
  'as'=&gt;'testItem'
  ]);
  </code></pre>
  
  <p>if anyone could help me solve the problem will be appreciated. </p>