disable field dynamically but save it in db

Hi, I need to dynamically disable a Togglebut I have to save the field: how come it doesn’t work ?
...
switch ($tipo) {
case SoggettoTipo::Contraente:
$is_contraente = true;
$is_contraente_disabled = true;
break;
case SoggettoTipo::DlDecRup:
$is_dldecrup = true;
$is_dldecrup_disabled = true;
break;
}
...
Toggle::make('is_contraente')
->default($is_contraente)
->dehydrated()
->disabled($is_contraente_disabled),
...
switch ($tipo) {
case SoggettoTipo::Contraente:
$is_contraente = true;
$is_contraente_disabled = true;
break;
case SoggettoTipo::DlDecRup:
$is_dldecrup = true;
$is_dldecrup_disabled = true;
break;
}
...
Toggle::make('is_contraente')
->default($is_contraente)
->dehydrated()
->disabled($is_contraente_disabled),
Solution:
Perfect !! ```php Forms\Components\Toggle::make('is_contraente') ->default($is_contraente) ->disabled($is_contraente_disabled)...
Jump to solution
4 Replies
Dennis Koch
Dennis Koch13mo ago
Because disabled() feels aren't saved
Marco Mapelli
Marco MapelliOP13mo ago
Ok, but with ->dehydrated() ??
Dennis Koch
Dennis Koch13mo ago
Not sure whether that works. But you specified disabled() after dehydrated() so it's overwritten again.
Solution
Marco Mapelli
Marco Mapelli13mo ago
Perfect !!
Forms\Components\Toggle::make('is_contraente')
->default($is_contraente)
->disabled($is_contraente_disabled)
->dehydrated(),
Forms\Components\Toggle::make('is_contraente')
->default($is_contraente)
->disabled($is_contraente_disabled)
->dehydrated(),
Thanks
Want results from more Discord servers?
Add your server