From 7a117017252761da76aaa7f4e1f1f8a81b210739 Mon Sep 17 00:00:00 2001 From: Roman Korchnev Date: Sun, 27 Oct 2024 07:31:44 +0300 Subject: [PATCH] added admin statistics --- app/Filament/Pages/Dashboard.php | 14 +++++++ app/Filament/Widgets/StatsOverview.php | 51 ++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 app/Filament/Pages/Dashboard.php create mode 100644 app/Filament/Widgets/StatsOverview.php diff --git a/app/Filament/Pages/Dashboard.php b/app/Filament/Pages/Dashboard.php new file mode 100644 index 0000000..9102ff4 --- /dev/null +++ b/app/Filament/Pages/Dashboard.php @@ -0,0 +1,14 @@ +pages([]); + } +} diff --git a/app/Filament/Widgets/StatsOverview.php b/app/Filament/Widgets/StatsOverview.php new file mode 100644 index 0000000..abc830a --- /dev/null +++ b/app/Filament/Widgets/StatsOverview.php @@ -0,0 +1,51 @@ +where('created_at', '>=', Carbon::now()->startOfMonth())->count()) + ->chart(self::getCountUsersRegisteredForLastMonth()) + ->color('success'), + Stat::make( + 'Активных пользователей', + User::query()->where('is_confirmed', true)->count() + ), + Stat::make( + 'Всего пользователей', + User::query()->count() + ), + ]; + } + + private function getCountUsersRegisteredForLastMonth(): array + { + $results = []; + $startTime = Carbon::now()->startOfMonth(); + $daysLeft = $startTime->diffInDays(Carbon::now()); + + for ($i = 0; $i < $daysLeft; $i++) { + $endTime = $startTime->copy()->addDay(); + $count = DB::table('users') + ->whereBetween('created_at', [ + $startTime, + $endTime, + ]) + ->count(); + $results[] = $count; + $startTime = $endTime; + } + + return $results; + } +}