Files
ai-nav/web10/app/Filament/Resources/CommentResource.php

127 lines
4.4 KiB
PHP
Raw Permalink Normal View History

2026-02-05 22:22:10 +08:00
<?php
namespace App\Filament\Resources;
use App\Filament\Resources\CommentResource\Pages;
use App\Filament\Resources\CommentResource\RelationManagers;
use App\Models\Comment;
use Filament\Forms;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
class CommentResource extends Resource
{
protected static ?string $model = Comment::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationLabel = '评论';
protected static ?string $navigationGroup = '内容管理';
public static function form(Form $form): Form
{
return $form
->schema([
Section::make('评论内容')
->schema([
TextInput::make('target_type')
->label('类型')
->disabled()
->dehydrated(false),
TextInput::make('target_id')
->label('目标 ID')
->disabled()
->dehydrated(false),
TextInput::make('nickname')
->label('昵称')
->disabled()
->dehydrated(false),
TextInput::make('email')
->label('邮箱')
->disabled()
->dehydrated(false),
Textarea::make('content')
->label('内容')
->disabled()
->dehydrated(false)
->columnSpanFull(),
])->columns(2),
Section::make('审核与回复')
->schema([
Select::make('status')
->label('状态')
->options([
'pending' => '待审',
'approved' => '通过',
'rejected' => '拒绝',
])
->required(),
Textarea::make('reply_content')
->label('回复内容')
->rows(3)
->nullable(),
])->columns(2),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('target_type')->label('类型')->sortable(),
TextColumn::make('target_id')->label('目标 ID')->sortable(),
TextColumn::make('nickname')->label('昵称')->searchable(),
TextColumn::make('status')->label('状态')->sortable(),
TextColumn::make('like_count')->label('点赞')->sortable(),
TextColumn::make('created_at')->label('创建时间')->dateTime(),
])
->filters([
Tables\Filters\SelectFilter::make('status')
->label('状态')
->options([
'pending' => '待审',
'approved' => '通过',
'rejected' => '拒绝',
]),
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
])
->emptyStateActions([
Tables\Actions\CreateAction::make(),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListComments::route('/'),
'create' => Pages\CreateComment::route('/create'),
'edit' => Pages\EditComment::route('/{record}/edit'),
];
}
public static function canCreate(): bool
{
return false;
}
}