How to validate Select relation field?
Hi guys, I have 3 simple models: Organization, Store, Contact. Each Contact can be assign to Store only of his own Organization. I want to use Select field with multiple option, but I need to validate that the stores saved in belongs to organization of that contact.
This works just fine, but user can select Organization first, then select some Stores, then change organization and click save. It will save organization with stores that dont belongs to that organization.
5 Replies
Add ->live to Forms\Components\Select::make('organization_id')
Hey, thank you, but still not working.
use ->AfterStateUpdated on the org to $set the other fields to null; and then on the fields that depend on that relation you modify the query like this
modifyQueryUsing: fn (Builder $query , Get $get) => $query->where(['team_id' => $get('team_id') ])
and where you put ->AfterStateUpdate, put ->live()
Thank you, this is what I was looking for. π
hmmm...would have thought the ->relationship handled the re-build without an additional afterstate...nevermind though.