F
Filamentβ€’6mo ago
Jamie Cee

Hiding multi-select options but only on edit - using relationships

Fieldset::make('Roles')
->schema([
Forms\Components\Select::make('roles')
->label('')
->multiple()
->relationship('roles', 'name')
->preload()
->required(),
])
->columns(1),
Fieldset::make('Roles')
->schema([
Forms\Components\Select::make('roles')
->label('')
->multiple()
->relationship('roles', 'name')
->preload()
->required(),
])
->columns(1),
I have the above, however. WHen it comes to editing, I want to hide the "admin" role if the record user is the same as the authenticated user (This is to prevent an admin from removing the admin role from themselves) but still allow them to give/take other roles from the system
11 Replies
Jamie Cee
Jamie Ceeβ€’6mo ago
Is it possible to pass the record as well? so if operation is edit, check that auth user matches the record user? Answered my own question. I should try things before asking a question 🀣 However, the other question is handling the data. Because it's the relationship. I can now hide admin, but it removes it when I delete another role
Lara Zeus
Lara Zeusβ€’6mo ago
not sure I got "but it removes it when I delete another role"
Jamie Cee
Jamie Ceeβ€’6mo ago
So if I edit the record and don't touch any of the roles, the user remains an admin. However, if I choose to remove the "user" role, it removes the admin role also. (currently only have the 2 roles). So wonder if it runs a sync function?
Lara Zeus
Lara Zeusβ€’6mo ago
I think you need to do two query if allowed to see admin role query with admin else query without the admin I bit there is a better way but dont know how πŸ™‚
Jamie Cee
Jamie Ceeβ€’6mo ago
Ill have a play around cheers. On a different note - if you have any ideas. When I create a new user, I am getting "field id doesn't have a default value" however, the primary key is set to use Uuid. This was working last week, only thing different was that I pulled in the latest release this morning
Lara Zeus
Lara Zeusβ€’6mo ago
umm I dont use uuid so not sure if there is any update to it πŸ€”
Jamie Cee
Jamie Ceeβ€’6mo ago
Apologies, I meant the latest release of filament was updated.
Lara Zeus
Lara Zeusβ€’6mo ago
I think filament dont care about the id type as long you set it in the model
Jamie Cee
Jamie Ceeβ€’6mo ago
Yeah might not be related. Just strange Can't actually find out how to obtain the relationship data. It doesn't come through in the data array either on handleRecordUpdate WOO, found how to do it