title: Laravel - return data group by month(and sum) and group by year
body: <p>I have this function below, which i got to it thanks to the help of <strong>everyone</strong> in <a href="https://stackoverflow.com/questions/53944966/laravel-get-data-by-month-and-sum-it-varchar">this</a> question:</p>
  
  <pre><code>$records = TabelaAngariacao::select('preco', 'created_at')
              -&gt;where('estado', '=', 'Vendido')
              -&gt;get()
              -&gt;groupBy(function($date) {
                  return Carbon::parse($date-&gt;created_at)-&gt;format('m');
              })-&gt;transform(function ($value) { //it can also be map()
  
                  $nStr = $value-&gt;map(function ($vl) {
                      return str_replace(".", "", $vl-&gt;preco);
                  });
                  return [
                      'preco_sum' =&gt; $nStr-&gt;sum()
                  ];
              });
  </code></pre>
  
  <p>...this function is great, i had a problem because i´m saving the preco(prices) has varchar(which is wrong), but by using map i´m able to sum, and everything is working great giving me the result below:</p>
  
  <pre><code>10: {preco_sum: 160000}
  11: {preco_sum: 220000}
  12: {preco_sum: 1175000}
  </code></pre>
  
  <p>I have the months and the sum of them...but...then i realize i need to have the same thing but also related to the year, so i tried this:</p>
  
  <pre><code>return Carbon::parse($date-&gt;created_at)-&gt;format('Y-m');
  </code></pre>
  
  <p>which leads me to this result:</p>
  
  <pre><code>"2018-10" =&gt; array:1 [▶]
  "2018-11" =&gt; array:1 [▶]
  "2018-12" =&gt; array:1 [▶]
  "2019-01" =&gt; array:1 [▶]
  </code></pre>
  
  <p>but <strong>how do i filter this by year on the client side?. I´m using chartjs, so one line should be all the months sumed OF 2018 and the same for 2017 for example.</strong>  </p>
  
  <p>Thanks for your time, regards</p>