$setup->startSetup(); $insertArray = array( 'profile_picture' => array("type" => "varchar", "label" => "Profile Picture"), 'security_question_1' => array("type" => "int", "label" => "Security Question 1"), 'security_question_2' => array("type" => "int", "label" => "Security Question 2"), 'security_answer_1' => array("type" => "varchar", "label" => "Security Answer 1"), 'security_answer_2' => array("type" => "varchar", "label" => "Security Answer 2") ); foreach ($insertArray as $key => $data) { $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->addAttribute(Customer::ENTITY, $key, [ 'type' => $data['type'], 'label' => $data['label'], 'input' => 'text', 'required' => false, 'visible' => true, 'user_defined' => true, 'sort_order' => 1000, 'position' => 1000, 'system' => 0, ]); $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, $key) ->addData([ 'attribute_set_id' => $attributeSetId, 'attribute_group_id' => $attributeGroupId, 'used_in_forms' => ['adminhtml_customer'], ]); $attribute->save(); } $setup->endSetup();