title: How to get the count of visits of 12 months of the year ( visits has checkup service in it services , total visits ) In Laravel
body: <p>I had tried to get it using the below approach, but it takes a long time. Is there a work around?</p>
  <pre class="lang-php prettyprint-override"><code>
  $clinic=$user-&gt;Clinics-&gt;first();
  
  $userPerMonth= array();
  for ($i=1; $i&lt;=12; $i++){
      $checkups = Visit::where('clinic_id', $clinic-&gt;id)
                       -&gt;whereMonth('created_at', date('m',strtotime('-'.$i.' month')))
                       -&gt;whereHas('VisitCheckUps')
                       -&gt;count();
          
       $userPerMonth[$i]=['checkups'=&gt;$checkups];
  }
  
  dump($userPerMonth);
  </code></pre>