KnowledgePointResource.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace App\Filament\Resources;
  3. use App\Filament\Resources\KnowledgePointResource\Pages;
  4. use App\Models\KnowledgePoint;
  5. use BackedEnum;
  6. use Filament\Actions\Action;
  7. use Filament\Actions\BulkActionGroup;
  8. use Filament\Actions\EditAction;
  9. use Filament\Schemas\Components\Section;
  10. use Filament\Forms\Components\TextInput;
  11. use Filament\Resources\Resource;
  12. use Filament\Schemas\Schema;
  13. use Filament\Tables;
  14. use Filament\Tables\Columns\TextColumn;
  15. use Filament\Tables\Filters\SelectFilter;
  16. use UnitEnum;
  17. class KnowledgePointResource extends Resource
  18. {
  19. protected static ?string $model = KnowledgePoint::class;
  20. protected static BackedEnum|string|null $navigationIcon = 'heroicon-o-share';
  21. protected static ?string $navigationLabel = '知识点';
  22. protected static ?string $modelLabel = '知识点';
  23. protected static ?string $pluralModelLabel = '知识点';
  24. protected static UnitEnum|string|null $navigationGroup = null;
  25. protected static ?int $navigationSort = 1;
  26. protected static bool $shouldRegisterNavigation = false;
  27. public static function form(Schema $schema): Schema
  28. {
  29. return $schema
  30. ->schema([
  31. Section::make('基础信息')
  32. ->schema([
  33. TextInput::make('kp_code')->required()->maxLength(64),
  34. TextInput::make('name')->required()->maxLength(255),
  35. TextInput::make('subject')->maxLength(64),
  36. TextInput::make('grade')->maxLength(32),
  37. TextInput::make('parent_kp_code')->maxLength(64),
  38. ])
  39. ->columns(2),
  40. ]);
  41. }
  42. public static function table(Tables\Table $table): Tables\Table
  43. {
  44. return $table
  45. ->columns([
  46. TextColumn::make('kp_code')->label('编码')->searchable(),
  47. TextColumn::make('name')->label('名称')->searchable(),
  48. TextColumn::make('subject')->label('学科')->sortable(),
  49. TextColumn::make('grade')->label('年级')->sortable(),
  50. TextColumn::make('updated_at')->label('更新')->dateTime(),
  51. ])
  52. ->filters([
  53. SelectFilter::make('subject')
  54. ->options([
  55. 'math' => '数学',
  56. 'physics' => '物理',
  57. ]),
  58. ])
  59. ->actions([
  60. Action::make('view')
  61. ->label('查看')
  62. ->icon('heroicon-o-eye')
  63. ->url(fn (KnowledgePoint $record) => static::getUrl('view', ['record' => $record])),
  64. EditAction::make(),
  65. ])
  66. ->bulkActions([
  67. BulkActionGroup::make([]),
  68. ]);
  69. }
  70. public static function getPages(): array
  71. {
  72. return [
  73. 'index' => Pages\ListKnowledgePoints::route('/'),
  74. 'create' => Pages\CreateKnowledgePoint::route('/create'),
  75. 'view' => Pages\ViewKnowledgePoint::route('/{record}'),
  76. 'edit' => Pages\EditKnowledgePoint::route('/{record}/edit'),
  77. ];
  78. }
  79. }