components([ Section::make('基本信息') ->schema([ TextInput::make('name') ->label('分类名称') ->required() ->maxLength(255) ->live(onBlur: true) ->afterStateUpdated(fn ($state, callable $set) => $set('slug', Str::slug($state))), TextInput::make('slug') ->label('URL 别名') ->required() ->unique(ignoreRecord: true) ->maxLength(255), Textarea::make('description') ->label('描述') ->rows(3) ->maxLength(500), FileUpload::make('cover_image') ->label('封面图片') ->image() ->directory('categories') ->imageEditor(), ]) ->columns(2), Section::make('设置') ->schema([ TextInput::make('sort_order') ->label('排序') ->numeric() ->default(0), Toggle::make('is_active') ->label('启用') ->default(true), ]) ->columns(2), ]); } public static function table(Table $table): Table { return $table ->columns([ ImageColumn::make('cover_image') ->label('封面') ->circular(), TextColumn::make('name') ->label('名称') ->searchable() ->sortable(), TextColumn::make('slug') ->label('别名') ->searchable(), TextColumn::make('posts_count') ->label('文章数') ->counts('posts') ->sortable(), TextColumn::make('sort_order') ->label('排序') ->sortable(), IconColumn::make('is_active') ->label('状态') ->boolean(), TextColumn::make('created_at') ->label('创建时间') ->dateTime('Y-m-d H:i') ->sortable() ->toggleable(isToggledHiddenByDefault: true), ]) ->defaultSort('sort_order') ->filters([ TernaryFilter::make('is_active') ->label('状态'), ]) ->actions([ EditAction::make(), DeleteAction::make(), ]) ->bulkActions([ \Filament\Actions\BulkActionGroup::make([ \Filament\Actions\DeleteBulkAction::make(), ]), ]); } public static function getRelations(): array { return [ // ]; } public static function getPages(): array { return [ 'index' => Pages\ListCategories::route('/'), 'create' => Pages\CreateCategory::route('/create'), 'edit' => Pages\EditCategory::route('/{record}/edit'), ]; } }