© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
26 replies
Prodex

Save MM relationship with single select

Hi,

I have a condition in my form that checks if a user has only permission to one "location" and if so, the select multiple should render as single select where the single location value is already selected. This is easy by just querying for one location and set it as default. But because the data structure expects a many to many relation I need to modify the save method to attach one single location to the MM table.

I tried it like this, but that doesn't work:
            return Forms\Components\Select::make('locations')
                ->label(trans('locations.singular'))
                ->disabled()
                ->options(Auth::user()->locations()->get()->pluck('name', 'id'))
                ->saveRelationshipsUsing(fn($data, $record) => $record->locations()->sync($data['locations']))
                ->disablePlaceholderSelection();
            return Forms\Components\Select::make('locations')
                ->label(trans('locations.singular'))
                ->disabled()
                ->options(Auth::user()->locations()->get()->pluck('name', 'id'))
                ->saveRelationshipsUsing(fn($data, $record) => $record->locations()->sync($data['locations']))
                ->disablePlaceholderSelection();


How should the code look like?
Thank you!
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Single select with belongsToMany relationship
FilamentFFilament / ❓┊help
3mo ago
Select with relationship default
FilamentFFilament / ❓┊help
3y ago
Select relationship
FilamentFFilament / ❓┊help
3y ago
SelectFilter with relationship help...
FilamentFFilament / ❓┊help
2y ago