I am working on a Filament form where the user will be able to toggle several items (call them options) on a model resource.
The way these might look is something like
ComponentsFieldset::make('Group 1')->schema([
ComponentsToggle::make('option_a')->label('Option a'),
ComponentsToggle::make('option_b')->label('Option b'),
]),
ComponentsFieldset::make('Group 2')->schema([
ComponentsToggle::make('option_y')->label('Option y'),
ComponentsToggle::make('option_z')->label('Option z'),
])
These options are then stored in a single options
column as JSON:
{
"group_1": ['option_a'],
"group_2": ['option_y', 'option_z']
}
If the model does not have group_1.option_b
, it simply doesn’t show up in the json object.
I’m trying to figure out how to use afterStateHydrated
, beforeStateDehydrated
, and/or dehydrateStateUsing
on in order to populate the interface and store data back to the database correctly, but it’s proving..challenging.
Any advice on how to get this to work correctly, other than to not use json here? I’m working with a legacy system, and priority one is getting something to work before I dig into trying to refactor the data model.