title: How to query users and group them in age range using laravel eloquent
body: <p>I want to query users and group them by age range</p>
  
  <p>This is what I have done so far</p>
  
  <pre><code>User::applicant()-&gt;get()
                  -&gt;groupBy(function ($item) {
                      return Carbon::parse($item-&gt;dob)-&gt;age;
                  })
                  -&gt;map(function ($collection) {
  
                      return $collection-&gt;count();
                  });
  </code></pre>
  
  <p>This is what I have got from above query</p>
  
  <p><a href="https://i.stack.imgur.com/kZfMj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kZfMj.png" alt="enter image description here"></a></p>
  
  <p>Now want to fetch collection and order by age range</p>
  
  <pre><code>18-24: 1,
  25-35: 5,
  36-45: 89,
  46+ : 84
  </code></pre>