Context: To give context, I am trying to create a graph with the months as the labels and the number of applications as the dataset.
My code:
$apps = Application::whereBetween('created_at', [
Carbon::now()->startOfYear(),
Carbon::now()->endOfYear(),
])
->get()
->groupBy(function ($val) {
return Carbon::parse($val->created_at)->format('M');
})
->toArray();
returns
array:3 [▼
"Jan" => array:2 [▶]
"Feb" => array:1 [▶]
"May" => array:1 [▶]
]
I want to create an array that produces this result:
['Jan', 'Feb', 'May']
I have tried using array keys, values, etc without any joy.
My Answer:
>subMonths(11), Carbon::now()])->get();
$months = $apps->groupBy(function($app) {
return Carbon::parse($app->created_at)->format('F');
})->map(function($month) {
return $month->count();
});
$topMonth = $months->max();
echo "The top month for applications is: " . $topMonth;
Rate this post
3 of 5 based on 4265 votesComments