Hiding multi-select options but only on edit - using relationships
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
custom query and inject the
$opration
to check if in edit form
https://filamentphp.com/docs/3.x/forms/fields/select#customizing-the-relationship-queryIs 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
not sure I got "but it removes it when I delete another role"
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?
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 π
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
umm I dont use uuid so not sure if there is any update to it π€
Apologies, I meant the latest release of filament was updated.
I think filament dont care about the id type as long you set it in the model
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