title: How to count relations in laravel
body: <p>How can I count for example the number of roles for a user?</p>
  
  <p>When I try this:</p>
  
  <pre><code>User::with('roles')-&gt;count();
  </code></pre>
  
  <p>it just counts the number of users.</p>
  
  <p>What I need is to return the number of roles per user. For example:</p>
  
  <pre><code>[
     {
       "id": 2,
       "name": "user",
       "roles": 2 
     },
     {
       "id": 3,
       "name": "user",
       "roles": 1 
     }
  ]
  </code></pre>