Today is 9/25/2019
I'm trying to query my visitor with in this year of 2019 only.
Then, I want to know how many are on
1,2,3,4,5,6,7,8,9
I've tried
$raw = Visitor::query()
->whereYear('created_at', now()->year -1)
->get()
->pluck('created_at');
$data = [];
foreach ($raw as $i=>$date) {
$data[$i] = Carbon::parse($date)->format('m');
if( Carbon::parse($date)->format('m')[0] != 0 ){
$data[$i] = Carbon::parse($date)->format('m');
}else{
$data[$i] = str_replace('0','',Carbon::parse($date)->format('m'));
}
}
// dd($data);
$dataValues = array_count_values($data);
dd($dataValues);
I got
array:5 [▼
8 => 314
9 => 916
10 => 764
11 => 827
12 => 765
]
Why would I get anything in the future since this month is only September (9) ?
Please help me correct it.
I was hoping to get sth like this
array:9 [▼
0 => 314
1 => 916
2 => 764
3 => 827
4 => 165
5 => 225
6 => 565
7 => 65
8 => 1265
]
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2mHkzGG
via IFTTT
Aucun commentaire:
Enregistrer un commentaire