How to dynamically control the configuration of other components in a form?

I need to change another option for selecting components I tried to write it but it doesn't work.

Is there any way to achieve this behavior?

Also attribute_ids changes I may change another component multilevel dependencies will be updated?

For example, a <- b <- c, when c is modified, b needs to be modified at the same time, and a can only be modified when b is done.

Forms\Components\Select::make('attribute_parent_ids')
    ->label('属性父级')
    ->options(ProductAttribute::whereNull('parent_id')
        ->pluck('title', 'id'))
    ->multiple()
    ->live(true)
    ->afterStateUpdated(function (
        Forms\Components\Select $component
    ) {

        /** @var Forms\Components\Select $select */
        $select = $component->getContainer()
            ->getComponent('valueIds');

        $options = ProductAttribute::whereNotNull('parent_id')
            ->whereIn('parent_id',
                $component->getState())
            ->pluck('title',
                'id');

        // remove is cancel options
        $newState =
            collect($select->getState())
                ->filter(function ($value) use (
                    $options
                ) {
                    return isset($options[$value]);
                })
                ->toArray();

        $select->state($newState)
            ->options($options);
    })
    ->nullable(),
Forms\Components\Select::make('attribute_ids')
    ->label('属性')
    ->options([])
    ->multiple()
    ->live(true)
    ->nullable()
    ->key('valueIds')
Was this page helpful?