0
I need to create a chart of reports from the beginning of the year to the present day. And my idea is to use a line chart that shows each month the value of a report defined by myself.
Example: in the month of January I sold 50 products, and in the month of February I sold 52 products, in the chart will appear only the month of January, February and the following month (current month, as an example).
To get the dates I’m using the Carbon API Here and to get the value of data from one month to the next, I am using an example below done by myself:
$quantidadeMesPassado = Produto::where(['teste'=>$teste])
->whereBetween('updated_at',[$comecoMes, $fimDoMes])
->get()
->count();
To $quantidadeMesPassado
takes the value in the database with one condition, the $comecoMesPassado
has the beginning of the month with the Carbon
and the $fimDoMes
owns the end of the month as shown below.
$comecoMes = Carbon::now()->startOfMonth();
$fimDoMes = Carbon::now()->endOfMonth();
But I’m doubtful to execute to create a array
of PHP
and spend every month from the beginning of the year until now (today is July, the array should not have August and other months ahead), automatically.
Below is an example I’m using in my code to get the value of the month.
$comecoJaneiro = new Carbon('first day of January');
$comecoFevereiro = new Carbon('first day of February');
$mes = $comecoJaneiro->month;
At first, I think the $quantidadeMesPassado
may be a array
that possesses the values of $comecoMes
and $fimDoMes
of all previous months of the current month. Doubt is how to know which are all previous months. For what $comecoMes
and $fimDoMes
be the array
possessing all beginnings of previous month and end of month.
What would be the alternative that could be using to take the value of each previous month and insert within one array
?
vc just want a list with all months of the year from January to the current month? or full name in Portuguese?
– rray
that, necessarily yes. I don’t know if it would be something giant to do that.
– Arthur Abitante
You have to exemplify this
array
editing your question?– novic
Okay, I just edited, at first the question is how to know all the previous months and insert in an array, to be exchanged with $comecoMes and $fimDoMes
– Arthur Abitante