Skip to content

Commit

Permalink
added admin statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
romo4ko committed Oct 27, 2024
1 parent c9b90a6 commit 7a11701
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/Filament/Pages/Dashboard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Filament\Pages;

use Filament\Pages\BasePage;
use Filament\Panel;

class Dashboard extends BasePage
{
public function panel(Panel $panel): Panel
{
return $panel->pages([]);
}
}
51 changes: 51 additions & 0 deletions app/Filament/Widgets/StatsOverview.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace App\Filament\Widgets;

use App\Models\User;
use Carbon\Carbon;
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
use Illuminate\Support\Facades\DB;

class StatsOverview extends BaseWidget
{
protected function getStats(): array
{
return [
Stat::make('Новых пользователей за этот месяц',
User::query()->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;
}
}

0 comments on commit 7a11701

Please sign in to comment.