© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
2 replies
mathioud

Multiple Select with belongsToMany relationship, saves but does not show selected after reload.

Hello,
I have two models Model: Product and Model: Secondary Traits.
Product model has a belongsToMany relationship with SecondaryTrait just like that:

public function secondaryTraits() :belongsToMany
{
    return $this->belongsToMany(SecondaryTrait::class, 'products_secondarytraits', 'product_id', 'secondaryTrait_id');
}
public function secondaryTraits() :belongsToMany
{
    return $this->belongsToMany(SecondaryTrait::class, 'products_secondarytraits', 'product_id', 'secondaryTrait_id');
}


Also the form element used is a Multiple Select:
Select::make('secondary_traits')
   ->preload()
   ->multiple()
   ->relationship('secondaryTraits', 'search_as')
Select::make('secondary_traits')
   ->preload()
   ->multiple()
   ->relationship('secondaryTraits', 'search_as')


(the 'search_as' column is what i want the user to see in the field, because of translations in other columns)

After i select the related secondarytraits and save, they are indeed stored in the DB,
but when I refresh the page, or visit the specific product's form again, there are no options populating the field.

Any ideas ?
Solution
Answer:

It just didn't like the

Select::make('secondary_traits'
Select::make('secondary_traits'
) line.

if i rename it to Whatever else, it's just fine.
Select::make(lalalala')
Select::make(lalalala')
works.
There is some kind of conflict with the relationship name , when i use a name same with the relation's with underscore, that stops it from working.
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Multiple Select with BelongsToMany relationship
FilamentFFilament / ❓┊help
3y ago
Single select with belongsToMany relationship
FilamentFFilament / ❓┊help
3mo ago
Multiple select filter does not reload
FilamentFFilament / ❓┊help
3y ago
Select with BelongsToMany without multiple()?
FilamentFFilament / ❓┊help
3y ago