Files
laralog/app/Filament/Widgets/BlogStats.php
T
ak 01861f8809 feat: 插件使用说明(usage)+ 页面缓存命中统计
- plugin.json 新增 usage 字段(多行文本),后台插件卡片折叠展示;四个内置插件补齐使用说明
- PageCacheMiddleware 记录命中/未命中计数(按日滚动),仪表盘新增「页面缓存」统计卡(条目数 + 命中率),用于判断前台缓存效果、是否需额外加速
- 文档与测试同步
2026-08-12 03:57:22 +08:00

37 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Filament\Widgets;
use App\Models\Comment;
use App\Models\Post;
use App\Models\User;
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
class BlogStats extends BaseWidget
{
protected static ?int $sort = 1;
protected function getStats(): array
{
$cache = \App\Blog\Support\PageCacheMiddleware::stats();
return [
Stat::make('文章', Post::published()->count())
->description('总浏览量 '.number_format((float) Post::sum('views')))
->icon('heroicon-o-document-text'),
Stat::make('评论', Comment::query()->where('status', 'published')->count())
->description('待审核 '.Comment::query()->where('status', 'pending')->count())
->icon('heroicon-o-chat-bubble-left-right'),
Stat::make('用户', User::count())
->icon('heroicon-o-users'),
Stat::make('页面缓存', $cache['count'].' 条')
->description('命中率 '.$cache['rate'].'%(命中 '.$cache['hits'].' / 未命中 '.$cache['misses'].',按日滚动)')
->icon('heroicon-o-bolt'),
];
}
}