How to prevent an element from being selected twice?

I am using a repeater to manage a pivot table like this: I don't want users to be able to attach the same affiliate twice
Repeater::make('campaignAffiliates')
->schema([
Forms\Components\Select::make("affiliate_id")->relationship('affiliate', 'company_name')->required()->columnSpanFull(),
Forms\Components\ToggleButtons::make('cap_type')->inline()
->live()->default('unlimited')
->options(['unlimited'=> 'Unlimited', 'daily'=>'Daily', 'weekly'=>'Weekly'])
->colors(['unlimited'=>'success', 'daily'=> 'warning', 'weekly'=>'primary']),
Forms\Components\TextInput::make('cap')->hidden(fn ($get) => $get("cap_type") == "unlimited")->numeric()

])->columns(2)
->relationship(),
Repeater::make('campaignAffiliates')
->schema([
Forms\Components\Select::make("affiliate_id")->relationship('affiliate', 'company_name')->required()->columnSpanFull(),
Forms\Components\ToggleButtons::make('cap_type')->inline()
->live()->default('unlimited')
->options(['unlimited'=> 'Unlimited', 'daily'=>'Daily', 'weekly'=>'Weekly'])
->colors(['unlimited'=>'success', 'daily'=> 'warning', 'weekly'=>'primary']),
Forms\Components\TextInput::make('cap')->hidden(fn ($get) => $get("cap_type") == "unlimited")->numeric()

])->columns(2)
->relationship(),
No description
1 Reply

Did you find this page helpful?