mardi 7 juillet 2020

count total users for each date laravel 5.2

i need help please i have mysql table :

id   username   password     created_at
1    admin       *****       2020-07-06
2    user        *****       2020-07-06
3    user2       *****       2020-07-07

my controller :

$count = User::where('created_at', '>=', Carbon::today()->subDays(10))
            ->get(['id', DB::raw("DATE_FORMAT(created_at,'%Y-%m-%d') as date")])
            ->pluck('id', 'date');

now the problem is when i see result, it give me for example

2020-07-06 : 2
2020-07-07 : 3

I know it give the id of user based on date, but what I want is to get the count of users on each date for example

2020-07-06 : 2
2020-07-07 : 1

I tried also

->get([count('id'), DB::raw("DATE_FORMAT(created_at,'%Y-%m-%d') as date")])...

But don't work. Please someone help me thanks ??



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire