get all users created in a month laravel

Solutions on MaxInterview for get all users created in a month laravel by the best coders in the world

showing results for - "get all users created in a month laravel"
Beatrice
29 Jun 2020
1$users = User::select('id', 'created_at')
2->get()
3->groupBy(function($date) {
4    //return Carbon::parse($date->created_at)->format('Y'); // grouping by years
5    return Carbon::parse($date->created_at)->format('m'); // grouping by months
6});
7
8$usermcount = [];
9$userArr = [];
10
11foreach ($users as $key => $value) {
12    $usermcount[(int)$key] = count($value);
13}
14
15for($i = 1; $i <= 12; $i++){
16    if(!empty($usermcount[$i])){
17        $userArr[$i] = $usermcount[$i];    
18    }else{
19        $userArr[$i] = 0;    
20    }
21}
22