代码示例
use Filament\\Forms\\Components\\Repeater;
use Filament\\Forms\\Components\\Repeater\\TableColumn;
use Filament\\Forms\\Components\\Select;
use App\\Models\\Subject;
use Filament\\Infolists\\Components\\TextEntry;
Repeater::make('course_schedule')
\->table(\[
TableColumn::make('节次/星期'),
TableColumn::make('周一'),
TableColumn::make('周二'),
TableColumn::make('周三'),
TableColumn::make('周四'),
TableColumn::make('周五'),
TableColumn::make('周六'),
TableColumn::make('周日'),
\])
\->schema(\[
TextEntry::make('period')
\->label('节次')
\->formatStateUsing(fn ($state) => "第{$state}节"),
Select::make('subject\_id1')
\->label('学科')
\->options($subjects)
\->required(),
Select::make('subject\_id2')
\->label('学科')
\->options($subjects)
\->required(),
Select::make('subject\_id3')
\->label('学科')
\->options($subjects)
\->required(),
Select::make('subject\_id4')
\->label('学科')
\->options($subjects)
\->required(),
Select::make('subject\_id5')
\->label('学科')
\->options($subjects)
\->required(),
Select::make('subject\_id6')
\->label('学科')
\->options($subjects)
\->required(),
Select::make('subject\_id7')
\->label('学科')
\->options($subjects)
\->required(),
\])
\->deletable(false) // 不允许删除
\->addable(false) // 不允许添加
\->defaultItems(7) // 默认7项
\->reorderableWithDragAndDrop(false) // 不允许拖拽排序
\->default(\[ // 默认数据
\[
'period' => 1,
'subject\_id1' => null,
'subject\_id2' => null,
'subject\_id3' => null,
'subject\_id4' => null,
'subject\_id5' => null,
'subject\_id6' => null,
'subject\_id7' => null,
\],
\[
'period' => 2,
'subject\_id1' => null,
'subject\_id2' => null,
'subject\_id3' => null,
'subject\_id4' => null,
'subject\_id5' => null,
'subject\_id6' => null,
'subject\_id7' => null,
\],
\[
'period' => 3,
'subject\_id1' => null,
'subject\_id2' => null,
'subject\_id3' => null,
'subject\_id4' => null,
'subject\_id5' => null,
'subject\_id6' => null,
'subject\_id7' => null,
\],
\[
'period' => 4,
'subject\_id1' => null,
'subject\_id2' => null,
'subject\_id3' => null,
'subject\_id4' => null,
'subject\_id5' => null,
'subject\_id6' => null,
'subject\_id7' => null,
\],
\[
'period' => 5,
'subject\_id1' => null,
'subject\_id2' => null,
'subject\_id3' => null,
'subject\_id4' => null,
'subject\_id5' => null,
'subject\_id6' => null,
'subject\_id7' => null,
\],
\[
'period' => 6,
'subject\_id1' => null,
'subject\_id2' => null,
'subject\_id3' => null,
'subject\_id4' => null,
'subject\_id5' => null,
'subject\_id6' => null,
'subject\_id7' => null,
\],
\[
'period' => 7,
'subject\_id1' => null,
'subject\_id2' => null,
'subject\_id3' => null,
'subject\_id4' => null,
'subject\_id5' => null,
'subject\_id6' => null,
'subject\_id7' => null,
\]
\])