Repeater with 2 Unique Key Combinations

Good morning, I have a case where a course has a cost based on a "mode" and "type". Initially, it was based only on the "mode", and this code in CourseResource worked perfectly:
use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
Repeater::make('modes')
->relationship()
->schema([
Select::make('mode_id')
->label('Mode')
->options(Mode::query()->pluck('name', 'id'))
->required()
->distinct()
->disableOptionsWhenSelectedInSiblingRepeaterItems(),
TextInput::make('cost')
->numeric()
->minValue(0)
->maxValue(999999.99)
->prefix('$')
->required()
])
use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
Repeater::make('modes')
->relationship()
->schema([
Select::make('mode_id')
->label('Mode')
->options(Mode::query()->pluck('name', 'id'))
->required()
->distinct()
->disableOptionsWhenSelectedInSiblingRepeaterItems(),
TextInput::make('cost')
->numeric()
->minValue(0)
->maxValue(999999.99)
->prefix('$')
->required()
])
But after adding the "type", I get errors when saving, errors when disabling the selects for the unique combination of types and modes, etc. My question is: Is there an established or standard way to handle the Repeater with 2 unique key combinations? Before: courses(id, name) modes(id, name) costs(id, [course_id, mode_id] unique, cost) Now: courses(id, name) modes(id, name) types(id, name) costs(id, [course_id, mode_id, type_id] unique, cost)
2 Replies
toeknee
toeknee2mo ago
Add a unique to each of the Select & Text with a debounce on the ->live() and check each value. https://filamentphp.com/docs/3.x/forms/validation#unique
Matthew
Matthew2mo ago
Add a compute column to the table, and use that
Want results from more Discord servers?
Add your server