Enum select with live() on Create and Edit form

Hi All,

I have a question, i use a select with Enum and some dependecie fields/fieldset on this value.

  Forms\Components\Select::make('row_type')
      ->label(Helpers::translate('Row Type'))
      ->options(RowType::class)
      ->default(RowType::NORMAL)
      ->live()
      ->required()
      ->native(false),


The fieldset

  Forms\Components\Fieldset::make(Helpers::translate('Product settings'))
      ->schema([])
      ->columns(12)
      ->visible(fn (Forms\Get $get): bool => $get('row_type') == RowType::NORMAL)


On create record this works, on edit record this works not.
That is because on create $get('row_type') is Enum and on Edit it is integer even tho i cast it in the model

    protected $casts = [
        'row_type' => RowType::class,
    ];


For now i have create a helper to get this to work.

    public static function GetValueFromEnum(mixed $enum)
    {
        if (is_numeric($enum)) {
            return $enum;
        }

        return $enum->value;
    }


This is how i use it now

->visible(fn (Forms\Get $get): bool => Helpers::GetValueFromEnum($get('row_type')) == RowType::NORMAL->value)


It works, but i think there is a better and simpler solution only dont know how.
Can anyone point me in the right direction?

Thanks
Was this page helpful?