M3: Filament 后台资源(文章/分类/评论/媒体/用户/友链)+ 博客设置页 + 仪表盘统计

This commit is contained in:
ak
2026-08-11 18:08:47 +08:00
parent 6214976a88
commit dee0208f1d
46 changed files with 1572 additions and 6 deletions
+28
View File
@@ -0,0 +1,28 @@
<?php
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
{
return [
Stat::make('文章', Post::published()->count())
->description('总浏览量 '.number_format(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'),
];
}
}
+37
View File
@@ -0,0 +1,37 @@
<?php
namespace App\Filament\Widgets;
use App\Models\Comment;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Filament\Widgets\TableWidget as BaseWidget;
class RecentComments extends BaseWidget
{
protected static ?int $sort = 2;
protected int|string|array $columnSpan = 'full';
public function table(Table $table): Table
{
return $table
->query(Comment::query()->latest('created_at')->limit(10))
->columns([
TextColumn::make('author_name')->label('作者'),
TextColumn::make('content')->label('内容')->limit(50),
TextColumn::make('post.title')->label('文章')->limit(30),
TextColumn::make('status')
->label('状态')
->badge()
->formatStateUsing(fn ($state) => match ($state) {
'published' => '已发布',
'pending' => '待审核',
'spam' => '垃圾',
default => $state,
}),
TextColumn::make('created_at')->label('时间')->dateTime('Y-m-d H:i'),
])
->paginated(false);
}
}