Files
laralog/app/Filament/Resources/Posts/Schemas/PostForm.php
T

93 lines
3.8 KiB
PHP

<?php
namespace App\Filament\Resources\Posts\Schemas;
use App\Support\MediaDisk;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\MarkdownEditor;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\Toggle;
use Filament\Schemas\Schema;
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
class PostForm
{
public static function configure(Schema $schema): Schema
{
return $schema
->components([
\Filament\Schemas\Components\Section::make('内容')
->columns(2)
->schema([
TextInput::make('title')
->label('标题')
->required()
->columnSpanFull(),
TextInput::make('slug')
->label('Slug(留空自动生成)'),
Select::make('category_id')
->label('分类')
->relationship('category', 'name'),
Select::make('content_format')
->label('内容格式')
->options([
'markdown' => 'Markdown',
'html' => 'HTML',
])
->default('markdown'),
Select::make('status')
->label('状态')
->options([
'published' => '已发布',
'draft' => '草稿',
'private' => '私密',
])
->default('published'),
MarkdownEditor::make('content')
->label('正文')
->required()
->columnSpanFull(),
]),
\Filament\Schemas\Components\Section::make('封面与摘要')
->columns(2)
->schema([
SpatieMediaLibraryFileUpload::make('cover')
->label('封面图')
->collection('cover')
->image()
->imageEditor()
->disk(MediaDisk::name())
->columnSpanFull(),
Textarea::make('excerpt')
->label('摘要(留空自动截取)')
->rows(3),
TextInput::make('keywords')
->label('关键词(逗号分隔)'),
]),
\Filament\Schemas\Components\Section::make('发布设置')
->columns(3)
->schema([
DateTimePicker::make('published_at')
->label('发布时间')
->default(now()),
Toggle::make('is_sticky')
->label('置顶'),
Toggle::make('close_comment')
->label('关闭评论'),
TextInput::make('read_password')
->label('阅读密码(留空公开)'),
TextInput::make('views')
->label('浏览量')
->numeric()
->disabled(),
TextInput::make('comment_count')
->label('评论数')
->numeric()
->disabled(),
]),
]);
}
}