title: Laravel 5.4 query by month
body: <p>I'm building a forum and now I want to show the message count for every user in a graph with <code>chart.js</code>.</p>
  
  <p>In Laravel 5.4 I've got this query:</p>
  
  <pre><code>return DB::table('message')
              -&gt;select(DB::raw('count(*) as messages, extract(month from message.created_at) as month'))
              -&gt;join('user', 'message.user_id', '=', 'user.id')
              -&gt;where('user.id', $user-&gt;id)
              -&gt;groupBy('month')
              -&gt;get();
  </code></pre>
  
  <p>But this does not show <code>0</code> if there are no messages in a <code>month</code>. </p>
  
  <p>So for example now I receive this:</p>
  
  <pre><code>[16, 38, 100]
  </code></pre>
  
  <p>But I need this:</p>
  
  <pre><code>[0, 0, 0, 16, 38, 100, 0, 8, 0, 0, 0, 0]
  </code></pre>
  
  <p>How could I get this result!?</p>
  
  <p>Thanks a lot</p>