143 lines
5.2 KiB
PHP
143 lines
5.2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Filament\Resources;
|
||
|
|
|
||
|
|
use App\Filament\Resources\ArticleResource\Pages;
|
||
|
|
use App\Filament\Resources\ArticleResource\RelationManagers;
|
||
|
|
use App\Models\Article;
|
||
|
|
use Filament\Forms;
|
||
|
|
use Filament\Forms\Components\DateTimePicker;
|
||
|
|
use Filament\Forms\Components\FileUpload;
|
||
|
|
use Filament\Forms\Components\MarkdownEditor;
|
||
|
|
use Filament\Forms\Components\Section;
|
||
|
|
use Filament\Forms\Components\Select;
|
||
|
|
use Filament\Forms\Components\TextInput;
|
||
|
|
use Filament\Forms\Components\Textarea;
|
||
|
|
use Filament\Forms\Form;
|
||
|
|
use Filament\Resources\Resource;
|
||
|
|
use Filament\Tables;
|
||
|
|
use Filament\Tables\Columns\TextColumn;
|
||
|
|
use Filament\Tables\Table;
|
||
|
|
|
||
|
|
class ArticleResource extends Resource
|
||
|
|
{
|
||
|
|
protected static ?string $model = Article::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('title')
|
||
|
|
->label('标题')
|
||
|
|
->required()
|
||
|
|
->maxLength(255),
|
||
|
|
TextInput::make('slug')
|
||
|
|
->label('Slug')
|
||
|
|
->required()
|
||
|
|
->maxLength(255),
|
||
|
|
Textarea::make('summary')
|
||
|
|
->label('摘要')
|
||
|
|
->rows(2)
|
||
|
|
->nullable(),
|
||
|
|
MarkdownEditor::make('content_md')
|
||
|
|
->label('正文')
|
||
|
|
->columnSpanFull()
|
||
|
|
->required(),
|
||
|
|
])->columns(2),
|
||
|
|
Section::make('媒体与标签')
|
||
|
|
->schema([
|
||
|
|
FileUpload::make('cover')
|
||
|
|
->label('封面')
|
||
|
|
->disk('public')
|
||
|
|
->directory('articles/cover')
|
||
|
|
->image()
|
||
|
|
->imagePreviewHeight('120')
|
||
|
|
->nullable(),
|
||
|
|
TextInput::make('author')
|
||
|
|
->label('作者')
|
||
|
|
->maxLength(255)
|
||
|
|
->nullable(),
|
||
|
|
Select::make('tags')
|
||
|
|
->label('标签')
|
||
|
|
->multiple()
|
||
|
|
->relationship('tags', 'name')
|
||
|
|
->preload(),
|
||
|
|
])->columns(2),
|
||
|
|
Section::make('状态与SEO')
|
||
|
|
->schema([
|
||
|
|
TextInput::make('view_count')
|
||
|
|
->label('浏览量')
|
||
|
|
->numeric()
|
||
|
|
->disabled()
|
||
|
|
->dehydrated(false),
|
||
|
|
Select::make('status')
|
||
|
|
->label('状态')
|
||
|
|
->options([
|
||
|
|
'draft' => '草稿',
|
||
|
|
'published' => '发布',
|
||
|
|
])
|
||
|
|
->required(),
|
||
|
|
DateTimePicker::make('published_at')
|
||
|
|
->label('发布时间')
|
||
|
|
->nullable(),
|
||
|
|
TextInput::make('seo_title')
|
||
|
|
->label('SEO 标题')
|
||
|
|
->maxLength(255)
|
||
|
|
->nullable(),
|
||
|
|
TextInput::make('seo_description')
|
||
|
|
->label('SEO 描述')
|
||
|
|
->maxLength(255)
|
||
|
|
->nullable(),
|
||
|
|
])->columns(2),
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function table(Table $table): Table
|
||
|
|
{
|
||
|
|
return $table
|
||
|
|
->columns([
|
||
|
|
TextColumn::make('title')->label('标题')->searchable()->sortable(),
|
||
|
|
TextColumn::make('status')->label('状态')->sortable(),
|
||
|
|
TextColumn::make('view_count')->label('浏览')->sortable(),
|
||
|
|
TextColumn::make('published_at')->label('发布时间')->dateTime(),
|
||
|
|
TextColumn::make('created_at')->label('创建时间')->dateTime(),
|
||
|
|
])
|
||
|
|
->filters([
|
||
|
|
//
|
||
|
|
])
|
||
|
|
->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\ListArticles::route('/'),
|
||
|
|
'create' => Pages\CreateArticle::route('/create'),
|
||
|
|
'edit' => Pages\EditArticle::route('/{record}/edit'),
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|