| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace App\Filament\Resources;
- use App\Filament\Resources\KnowledgePointResource\Pages;
- use App\Models\KnowledgePoint;
- use BackedEnum;
- use Filament\Actions\Action;
- use Filament\Actions\BulkActionGroup;
- use Filament\Actions\EditAction;
- use Filament\Schemas\Components\Section;
- use Filament\Forms\Components\TextInput;
- use Filament\Resources\Resource;
- use Filament\Schemas\Schema;
- use Filament\Tables;
- use Filament\Tables\Columns\TextColumn;
- use Filament\Tables\Filters\SelectFilter;
- use UnitEnum;
- class KnowledgePointResource extends Resource
- {
- protected static ?string $model = KnowledgePoint::class;
- protected static BackedEnum|string|null $navigationIcon = 'heroicon-o-share';
- protected static ?string $navigationLabel = '知识点';
- protected static ?string $modelLabel = '知识点';
- protected static ?string $pluralModelLabel = '知识点';
- protected static UnitEnum|string|null $navigationGroup = null;
- protected static ?int $navigationSort = 1;
- protected static bool $shouldRegisterNavigation = false;
- public static function form(Schema $schema): Schema
- {
- return $schema
- ->schema([
- Section::make('基础信息')
- ->schema([
- TextInput::make('kp_code')->required()->maxLength(64),
- TextInput::make('name')->required()->maxLength(255),
- TextInput::make('subject')->maxLength(64),
- TextInput::make('grade')->maxLength(32),
- TextInput::make('parent_kp_code')->maxLength(64),
- ])
- ->columns(2),
- ]);
- }
- public static function table(Tables\Table $table): Tables\Table
- {
- return $table
- ->columns([
- TextColumn::make('kp_code')->label('编码')->searchable(),
- TextColumn::make('name')->label('名称')->searchable(),
- TextColumn::make('subject')->label('学科')->sortable(),
- TextColumn::make('grade')->label('年级')->sortable(),
- TextColumn::make('updated_at')->label('更新')->dateTime(),
- ])
- ->filters([
- SelectFilter::make('subject')
- ->options([
- 'math' => '数学',
- 'physics' => '物理',
- ]),
- ])
- ->actions([
- Action::make('view')
- ->label('查看')
- ->icon('heroicon-o-eye')
- ->url(fn (KnowledgePoint $record) => static::getUrl('view', ['record' => $record])),
- EditAction::make(),
- ])
- ->bulkActions([
- BulkActionGroup::make([]),
- ]);
- }
- public static function getPages(): array
- {
- return [
- 'index' => Pages\ListKnowledgePoints::route('/'),
- 'create' => Pages\CreateKnowledgePoint::route('/create'),
- 'view' => Pages\ViewKnowledgePoint::route('/{record}'),
- 'edit' => Pages\EditKnowledgePoint::route('/{record}/edit'),
- ];
- }
- }
|