Preserve data across form wizard steps

I have a 2 step form wizard, with a meal_type_id field in step 1, which I want to preserve for step 2.

This is what I have tried so far.
In the meal_type_id field, I have tried to set the $state to a selected_meal_type_id variable like so:
Select::make('meal_type_id')
                ->options(function (Get $get) {
                    $group = Group::find($get('group_id'));
                    return $group->mealTypes->pluck('name', 'id');
                })
                ->live()
                ->afterStateUpdated(function (Set $set, $state) {
                    $set('selected_meal_type_id', $state);
                })
                ->required(),

Then in my repeater function in step 2, I want to Get this data in a Select field:
public static function getItemsRepeater(): Repeater
    {
        return Repeater::make('productUserOrders')
            ->relationship()
            ->schema([
                Select::make('product_id')
                    ->label('Product')
                    ->options(function (Get $get, $state) {
                        $mealTypeId = $get('selected_meal_type_id');
                        if(! $mealTypeId) {
                            return [];
                        }
                        $mealType = MealType::find($mealTypeId);    
                        return $mealType->products->pluck('name', 'id');
                    })
                    ->required()
                    ->live()
                    ->afterStateUpdated(fn ($state, Set $set) => $set('price', Product::find($state)?->price ?? 0))               
                    ->distinct()
                    ->columnSpan([
                        'md' => 5,
                    ]),
            ])
            ->hiddenLabel()
            ->columns([
                'md' => 10,
            ])
            ->required();
    }


But it seems like the data is not preserved from step 1 to step 2. What am I doing wrong?
Was this page helpful?