Β© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filamentβ€’3y agoβ€’
41 replies
Tony

Problem with two select fields using same relationship

I have a polymorphic relationship of filters, Filters have a column describing its type, lets say A and B

I want 2 select fields on related model forms, using the third parameter of the relationship() method, i scope the results to one kind (A) or another (B)

Example:
Select::make('a')
  ->label('A')
  ->multiple()
  ->searchable()
  ->relationship('filters', 'name', fn (Builder $query) => $query->where('type', 'a')),
Select::make('b')
  ->label('B')
  ->multiple()
  ->searchable()
  ->relationship('filters', 'name', fn (Builder $query) => $query->where('type', 'b'))
Select::make('a')
  ->label('A')
  ->multiple()
  ->searchable()
  ->relationship('filters', 'name', fn (Builder $query) => $query->where('type', 'a')),
Select::make('b')
  ->label('B')
  ->multiple()
  ->searchable()
  ->relationship('filters', 'name', fn (Builder $query) => $query->where('type', 'b'))


The problem is that the last field on the form for the same relationship, in this case "b" is overwriting the value from the "a" select, i would need it to just add its values to the relationship, but not overwriting it, because of this problem, the only usable select field is the last one in the form, which has scoped values to only show one of the kinds of filters

I want to separate the two kinds of filters in different select fields, i know that if i only used one field and didn't scope the options, it would work, but i want to know if there is any way to do it πŸ‘€
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

Relationship between two dependent select fields
FilamentFFilament / β“β”Šhelp
3y ago
Concat two form fields with multiple select relationship
FilamentFFilament / β“β”Šhelp
3y ago
Pivot Select using Relationship
FilamentFFilament / β“β”Šhelp
2w ago