title: How to count table column values and print in blade file laravel 5.6
body: <p>I am working with <code>laravel 5.6</code> and I have table named <code>vehicles</code> with columns <code>categoryname</code>:</p>
  
  <pre><code>id   number  categoryname
  1    123       Car
  2    589       Van
  3    589       Car
  4    563       SUV
  5    563       Van
  </code></pre>
  
  <p>Now I have following <code>blade</code> view in <code>welcome.blade.php</code>: </p>
  
  <pre><code>&lt;img src="{{URL::asset('/images/car.png')}}" alt="profile Pic" height="50" width="50" class="center-block"&gt;
                          &lt;div&gt;Car&lt;/div&gt;
  
                          &lt;div&gt;text text text texttext texttext texttext text trtrttr rrttrtr rrtrttr rtrtrttrtr rtrttrtr rrtrttr rrtrtr&lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="col-md-3 text-center"&gt;
                          &lt;img src="{{URL::asset('/images/van.png')}}" alt="profile Pic" height="50" width="50" class="center-block"&gt;
                          &lt;div&gt;Van&lt;/div&gt;
  
                          &lt;div&gt;text text text texttext texttext texttext text trtrttr rrttrtr rrtrttr rtrtrttrtr rtrttrtr rrtrttr rrtrtr&lt;/div&gt;
                          &lt;/div&gt;
  </code></pre>
  
  <p>My problem is now I need count same values in <code>categoryname</code> column and print them like this way in <code>welcome.blade.php</code>.</p>
  
  <pre><code>&lt;div&gt;Car&lt;/div&gt;
  &lt;div&gt;2&lt;/div&gt;
  
  &lt;div&gt;Van&lt;/div&gt;
  &lt;div&gt;3&lt;/div&gt;
  
  etc...
  </code></pre>
  
  <p>I have following controller to count column values:</p>
  
  <pre><code>$names = Vehicle::groupBy('categoryname')-&gt;select('id', 'categoryname', \DB::raw('COUNT(*) as cnt'))-&gt;get(); 
  </code></pre>
  
  <p>It is working however I need <code>print</code> its values under vehicles <code>categories</code> in blade file.</p>
  
  <p>How can I achieve this?</p>
  
  <p><strong>Image</strong>
  <a href="https://i.stack.imgur.com/FPb1d.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FPb1d.png" alt="weicome.blade.php file here"></a></p>
  
  <p><strong>hope to do this dynamicaly with relationship</strong>
  I have 2 models as Category and Vehicles with following relationship Category</p>
  
  <pre><code>public function vehicles()
      {
          return $this-&gt;hasMany(Vehicle::class);
      }
  
  public function category()
      {
          return $this-&gt;belongsTo(Category::class);
      }
  </code></pre>
  
  <p>and categories table name as following</p>
  
  <pre><code>id   categoryname   images
  1   Car             car.png
  2   Van             van.png
  3   SUV             suv.png
  etc
  </code></pre>
  
  <p>then how can I print categoryname and images from categories table and categoryname values counts using vehicles table and print all in same loop?</p>