schema([ Forms\Components\Section::make('分類資訊') ->schema([ Forms\Components\TextInput::make('name') ->label('分類名稱') ->required() ->maxLength(255) ->live(onBlur: true) ->afterStateUpdated(function (string $operation, $state, Forms\Set $set) { if ($operation === 'create') { $set('slug', Str::slug($state)); } }), Forms\Components\TextInput::make('slug') ->label('Slug (URL 友善)') ->required() ->unique(Category::class, 'slug', ignoreRecord: true) ->maxLength(255) ->helperText('URL 友善的標識符,例如:event, news, landing-event'), ]) ->columns(2), ]); } public static function table(Table $table): Table { return $table ->columns([ Tables\Columns\TextColumn::make('id') ->label('ID') ->sortable(), Tables\Columns\TextColumn::make('name') ->label('分類名稱') ->searchable() ->sortable(), Tables\Columns\TextColumn::make('slug') ->label('Slug') ->searchable() ->sortable() ->copyable() ->badge() ->color('info'), Tables\Columns\TextColumn::make('posts_count') ->label('文章數') ->counts('posts') ->sortable() ->badge() ->color('success'), Tables\Columns\TextColumn::make('created_at') ->label('建立時間') ->dateTime('Y-m-d H:i') ->sortable() ->toggleable(isToggledHiddenByDefault: true), Tables\Columns\TextColumn::make('updated_at') ->label('更新時間') ->dateTime('Y-m-d H:i') ->sortable() ->toggleable(isToggledHiddenByDefault: true), ]) ->filters([ // ]) ->actions([ Tables\Actions\EditAction::make(), Tables\Actions\DeleteAction::make(), ]) ->bulkActions([ Tables\Actions\BulkActionGroup::make([ Tables\Actions\DeleteBulkAction::make(), ]), ]) ->defaultSort('id', 'asc'); } 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'), ]; } }