F
Filament2y ago
Vp

Use another field to store in database

I think I saw something like this in docs, but now I cannot find.. I have key (string) and value (string) in database.. i want to display key in label and update value in DB Is it possible?
Forms\Components\TextInput::make('key')
->label(fn (string $state): string => __("message.{$state}"))
->numeric()
->suffix(fn (string $state) => $state == 'time' ? 'minutes' : ''),
Forms\Components\TextInput::make('key')
->label(fn (string $state): string => __("message.{$state}"))
->numeric()
->suffix(fn (string $state) => $state == 'time' ? 'minutes' : ''),
4 Replies
Vp
VpOP2y ago
I think there is easy ->something('value') to change, but not sure Now I change my method like below, I got what I need.. but still is there any better way
Forms\Components\TextInput::make('value')
->label(fn (Model $record) => __("message.{$record->key}"))
->numeric()
->suffix(fn (Model $record) => $record->key == 'time' ? 'minutes' : '')
Forms\Components\TextInput::make('value')
->label(fn (Model $record) => __("message.{$record->key}"))
->numeric()
->suffix(fn (Model $record) => $record->key == 'time' ? 'minutes' : '')
Dan Harrin
Dan Harrin2y ago
you would pass the key into make()
Vp
VpOP2y ago
Yes, in my original question I passed, and it update my 'key' in DB.. but I want to update 'value' field
cheesegrits
cheesegrits2y ago
Your second code example looks like the right way, I can't think of any other way to do it.
Want results from more Discord servers?
Add your server