Apply changes to field's sibling from Repeater

Using a column called is_primary_contact to a Parent model, I want to use $set() to apply changes to all of the parents. There can be only 1 primary contact, so If I set the parent1 to is_primary_contact, the rest of the parents should be false.

Select::make('is_primary_contact')
                        ->label('Is this parent the Primary Contact? (Only 1 parent can be the Primary Contact)')
                        ->options([
                            1 => 'Yes',
                            0 => 'No'
                        ])
                        ->required()
                        ->reactive()
                        ->afterStateUpdated(function(Closure $get, Closure $set, $state){

                            if($state == 1)
                            {   
                                $parentsRepeater = $get('../../parents');

                                foreach($parentsRepeater as $repeaterItemUuid => $parentItem)
                                {
                                    // How??
                                }
                            }
                            
                            $this->autoSaveParent($get('id'),'is_primary_contact', $state);
                        }),
Was this page helpful?