Search
 
SCRIPT & CODE EXAMPLE
 

PHP

get all users created in a month laravel

$users = User::select('id', 'created_at')
->get()
->groupBy(function($date) {
    //return Carbon::parse($date->created_at)->format('Y'); // grouping by years
    return Carbon::parse($date->created_at)->format('m'); // grouping by months
});

$usermcount = [];
$userArr = [];

foreach ($users as $key => $value) {
    $usermcount[(int)$key] = count($value);
}

for($i = 1; $i <= 12; $i++){
    if(!empty($usermcount[$i])){
        $userArr[$i] = $usermcount[$i];    
    }else{
        $userArr[$i] = 0;    
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: get admin url wordpress 
Php :: php combine 2 arrays keep duplicates 
Php :: array push in php 
Php :: php function 
Php :: laravel imap - Get message attachments 
Php :: html in php 
Php :: UUIDs LARAVEL 
Php :: laravel request validation rules for create and update 
Php :: generate fake name php 
Php :: how to assign variable in php 
Php :: laravel make:middleware 
Php :: valet select php version 
Php :: update cart subtotal woocommerce 
Php :: FPDF invoice Tutorial 
Php :: php interval day value 
Php :: how to create constant in php 
Php :: Databases supported by php 
Php :: link to internal pages in wp php 
Php :: construct php 
Php :: php while loop 
Php :: display data from two dimensional array in vew laravel 
Php :: $ is not define in laravel 
Php :: laravel migration column types 
Php :: woocommerce disable links on specific product 
Php :: how to check if file is empty in php 
Php :: how to get stripe processing fees api 
Php :: php method type hinting 
Php :: Automatic Subdomain with PHP 
Php :: unique check two clolumn in laravel validation 
Php :: laravel where and blade 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =