F
Filament14mo ago
Remi

Repeater based on other iterations

I want to create a repeater that allows a user to attach multiple locations, but every locations only once. so far i got this:
Forms\Components\Repeater::make('clientLocations')
->label(__('Locations'))
->live()
->relationship()
->orderColumn('order')
->simple(
Forms\Components\Select::make('location_id')
->live()
->relationship('location', 'name')
->required()
),
Forms\Components\Repeater::make('clientLocations')
->label(__('Locations'))
->live()
->relationship()
->orderColumn('order')
->simple(
Forms\Components\Select::make('location_id')
->live()
->relationship('location', 'name')
->required()
),
This allows me to create multiple attachments, but i can attach every location multiple times. i got this far, but this removes all the attached locations
Forms\Components\Repeater::make('clientLocations')
->label(__('Locations'))
->live()
->relationship()
->orderColumn('order')
->simple(
Forms\Components\Select::make('location_id')
->live()
->relationship('location', 'name', function (Builder $query, Get $get) {
Log::info(json_encode($get('../../clientLocations')));
return $query->whereNotIn('id',array_column($get('../../clientLocations'), 'location_id'));
})
->required()
),
Forms\Components\Repeater::make('clientLocations')
->label(__('Locations'))
->live()
->relationship()
->orderColumn('order')
->simple(
Forms\Components\Select::make('location_id')
->live()
->relationship('location', 'name', function (Builder $query, Get $get) {
Log::info(json_encode($get('../../clientLocations')));
return $query->whereNotIn('id',array_column($get('../../clientLocations'), 'location_id'));
})
->required()
),
2 Replies
toeknee
toeknee14mo ago
You need to loop through and check if this one has been set, then disable it. Let me check as Hugh was doing a PR to disable them too @Hugh Messenger how did you get on with your PR for the single option selector?
cheesegrits
cheesegrits14mo ago
It's in the queue. Dan has been slam dunked busy, so only high priority / bug fix PR's have been making progress. Got some movement on it today, so hopefully soon. I'll fix the language suggestion today. https://github.com/filamentphp/filament/pull/8635
GitHub
Add distinct() API to repeater by cheesegrits · Pull Request #863...
Changes have been thoroughly tested to not break existing functionality. New functionality has been documented or existing documentation has been updated to reflect changes. Visual changes are ex...
Want results from more Discord servers?
Add your server