F
Filament2d ago
Vp

Single select with belongsToMany relationship

I have a tenant system, users with teams. I want to create user and attach it to teams (team_user database), but I want to select only one team on select form because user can be in one team only, not on multiple. how can I do this correctly?
Select::make('team')
->relationship('teams', 'name')
// ->multiple() // if enable, works correctly
->preload(),
Select::make('team')
->relationship('teams', 'name')
// ->multiple() // if enable, works correctly
->preload(),
Solution:
I use normal Select or relationship (without multiple) and handle manually using Lifecycle Hooks
Jump to solution
3 Replies
Azad Furkan ŞAKAR
Not best solution but maybe you can use like this;
Select::make('team')
->relationship('teams', 'name')
->multiple()
->maxItems(1) // you can force to user only select one item
->preload(),
Select::make('team')
->relationship('teams', 'name')
->multiple()
->maxItems(1) // you can force to user only select one item
->preload(),
Vp
VpOP2d ago
This prevent multi select, but UI is not great IMO
Solution
Vp
Vp2d ago
I use normal Select or relationship (without multiple) and handle manually using Lifecycle Hooks

Did you find this page helpful?