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'); } Also the form element used is a Multiple Select: 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') line....
Jump to solution
1 Reply
Solution
mathioud
mathioud13mo ago
Answer: It just didn't like the Select::make('secondary_traits') line. if i rename it to Whatever else, it's just fine. 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.
Want results from more Discord servers?
Add your server