I need to group and count all items by mês
. I use Laravel 5.2
, I tried to do this:
$mes = date('m');
$vendas = Encomenda::where('FlgStEncomenda', 'O')
->group("MONTH(created_at)={$mes}")
->count();
I need it to return like this:
[0] 5
[1] 10
[2] 4
[3] 11
[4] 107
[5] 110
[6] 120
[7] 5
[8] 103
[9] 104
[10] 102
[11] 0
Where índice
means mês
, and in the case of the month that has not yet arrived return 0. Can you do this with Eloquente
?