41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
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);
|
|
}
|
|
}
|