Based on the provided code snippet, it seems that the issue lies in the usage of the hidden and required methods in the Select field. The hidden method is used to conditionally hide the field based on the value of the key_contact toggle, while the required method is used to conditionally make the field required when the key_contact toggle is true.
To fix the issue, you can try modifying the code as follows:
Forms\Components\Toggle::make('key_contact')
->label('Key Contact'),
Forms\Components\Select::make('key_reason_id')
->relationship(name: 'keyReason', titleAttribute: 'name')
->label('Key Reason')
->native(false)
->display(fn (Get $get) => $get('key_contact') == true)
->required(fn (Get $get) => $get('key_contact') == true)
->validationAttribute('Key Contact Reason'),
In the modified code, the hidden method has been replaced with the display method. The display method is used to conditionally show the field based on the value of the key_contact toggle. This ensures that the Select field is displayed to the user when the key_contact toggle is true.
Please note that this solution assumes that the display method is available in the FilamentPHP version you are using. If not, you may need to check the FilamentPHP documentation or consult the FilamentPHP community for alternative solutions.