2
I need to group and count all items by mês
. Utilise Laravel 5.2
, tried to do so:
$mes = date('m');
$vendas = Encomenda::where('FlgStEncomenda', 'O')
->group("MONTH(created_at)={$mes}")
->count();
I need you to come back 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 the índice
means the mês
, and in the case of the month that has not yet arrived return 0. It has to do this with Eloquente
?
To return 0 you’ll have to make one
array
manually 1 to 12 or create a table of months in your base and make aRight Join
.– Diego Souza
It would be nice to create the table, would be cleaner the code.
– Diego Souza