Encrypted cast doesn't load into inputs when using $hidden cast.

Since this is sensitive information, I don't want to accidentally leak it somewhere in payload on the front facing application hence I put those values into $hidden. But now I have and issue with it, when using Filament as admin, I want to make exception here and still load this data. What would be proper way to handle this?
Forms\Components\TextInput::make('api_key')
->label('API Key')
->default(fn ($record) => $record?->api_key),

Forms\Components\TextInput::make('api_secret')
->label('API Secret'),
Forms\Components\TextInput::make('api_key')
->label('API Key')
->default(fn ($record) => $record?->api_key),

Forms\Components\TextInput::make('api_secret')
->label('API Secret'),
3 Replies
KillAuro
KillAuro4w ago
if you have isAdmin method in user model, you can do like following:
use Filament\Facades\Filament;

Forms\Components\TextInput::make('api_key')
->label('API Key')
->default(fn ($record) => $record?->api_key)
->visible(fn () => auth()->check() && auth()->user()->isAdmin()),

Forms\Components\TextInput::make('api_secret')
->label('API Secret')
->default(fn ($record) => $record?->api_secret)
->visible(fn () => auth()->check() && auth()->user()->isAdmin()),
use Filament\Facades\Filament;

Forms\Components\TextInput::make('api_key')
->label('API Key')
->default(fn ($record) => $record?->api_key)
->visible(fn () => auth()->check() && auth()->user()->isAdmin()),

Forms\Components\TextInput::make('api_secret')
->label('API Secret')
->default(fn ($record) => $record?->api_secret)
->visible(fn () => auth()->check() && auth()->user()->isAdmin()),
Sam Axe
Sam AxeOP4w ago
extremely useful to know, thank you

Did you find this page helpful?