Disabling Input Fields on Filament Form Edit Page with User Verification How can I make it so that personal data cannot be modified by the admin user on the edit page?
Here’s how I solved it, but I’m not sure if this is the best solution or if there might be a more efficient one. Thank you.
Sample code:
Forms\Components\TextInput::make('lastname')
->label(__('fields.property_agency_lastname'))
->default($user_profile->lastname)
->disabled(Filament::auth()->user()->email == "[email protected] ")
->required(),
Forms\Components\TextInput::make('firstname')
->label(__('fields.property_agency_firstname'))
->default($user_profile->firstname)
->disabled(Filament::auth()->user()->email == "[email protected] ")
->required(),
Forms\Components\TextInput::make('mobil')
->label(__('fields.property_agency_mobil'))
->default($user_profile->mobil)
->disabled(Filament::auth()->user()->email == "[email protected] ")
->required(),
Forms\Components\TextInput::make('email')
->label(__('fields.property_agency_email'))
->default($user_data->email)
->disabled(Filament::auth()->user()->email == "[email protected] ")
->required(),
Hello mate,
Instead of using the admin e-mail, I would suggest using roles for situations like this:
Filament::auth()->user()->hasRole('admin');
Also, if you only have one admin, this solution is sufficient. Just consider summarizing all conditions into a single variable, such as:
$fooCondition = Filament::auth()->user()->email == "[email protected] ";
or
$adminCondition = Filament::auth()->user()->hasRole('admin');
@omeratayilmaz
Yes, the site has one admin. That's why I considered email verification. I set it up so that at the /admin URL, it retrieves administrator data from the admins table, while at the /agency URL, it retrieves data from the users table.
Do you have any idea why ->default($user_profile->lastname) isn’t showing up on the edit page? What could be causing this?
Please sign in or create an account to participate in this conversation.