I have created custom customer attribute and use at registration process. Its working fine.
Now I want update attribute like - previously its 'required'=> false
. Now I want to set it as 'required'=> true
.
But don't know how to upgrade it using UpgradeData.php
Plz help to solve this.
I tried with below code -
if (version_compare($context->getVersion(), "1.0.6", "<"))
{
/** @var CustomerSetup $customerSetup */
$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
$customerEntity = $customerSetup->getEavConfig()->getEntityType('customer');
$attributeSetId = $customerEntity->getDefaultAttributeSetId();
/** @var $attributeSet AttributeSet */
$attributeSet = $this->attributeSetFactory->create();
$attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);
$customerSetup->updateAttribute(\Magento\Customer\Model\Customer::ENTITY, 'netz_allowed', [
'visible_on_front' => 1,
'input' => 'select',
'require' => true,
'source' => 'Magento\Config\Model\Config\Source\Yesno',
]);
$attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'netz_allowed')
->addData(['used_in_forms' => ['customer_account_create','customer_account_edit']]);
$attribute->save();
}
$setup->endSetup();