Q:

add custom attribute for customer in magento 2.3 using db schema

how I can add a custom attribute for customer 
using DB schema in Magento 2.3
does anyone is already tried 
Just help me?

A:

You can use the below code in your module's Setup/InstallData.php
<?php
namespace Vendor\CustomerAttribute\Setup;

use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Customer\Model\Customer;
use Magento\Customer\Setup\CustomerSetupFactory;

class InstallData implements InstallDataInterface
{
    private $customerSetupFactory;
    /**
     * Constructor
     *
     * @param \Magento\Customer\Setup\CustomerSetupFactory $customerSetupFactory
     */
    public function __construct(
        CustomerSetupFactory $customerSetupFactory
    ) {
        $this->customerSetupFactory = $customerSetupFactory;
    }

    /**
     * {@inheritdoc}
     */
    public function install(
        ModuleDataSetupInterface $setup,
        ModuleContextInterface $context
    ) {
        $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);

        $customerSetup->addAttribute(\Magento\Customer\Model\Customer::ENTITY, 'custom_telephone', [
            'type' => 'varchar',
            'label' => 'custom_telephone',
            'input' => 'text',
            'source' => '',
            'required' => true,
            'visible' => true,
            'position' => 333,
            'system' => false,
            'backend' => ''
        ]);

        $attribute = $customerSetup->getEavConfig()->getAttribute('customer', 'custom_telephone')
        ->addData(['used_in_forms' => [
                'adminhtml_customer',
                'adminhtml_checkout',
                'customer_account_create',
                'customer_account_edit'
            ]
        ]);
        $attribute->save();
    }
}

Hope it will work for you.

A:

It can be achieved using DataPatchInterface
    

namespace Vendor_Name\Module_Name\Setup\Patch\Data; 

use Magento\Customer\Setup\CustomerSetupFactory;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Eav\Model\Entity\Attribute\SetFactory as AttributeSetFactory;

class BuiltEav implements DataPatchInterface {

private $moduleDataSetup;
protected $customerSetupFactory;
private $eavSetupFactory;

public function __construct(
    ModuleDataSetupInterface $moduleDataSetup,
    CustomerSetupFactory $customerSetupFactory,
    AttributeSetFactory $attributeSetFactory
) {
    $this->moduleDataSetup = $moduleDataSetup;
    $this->attributeSetFactory = $attributeSetFactory;
    $this->customerSetupFactory = $customerSetupFactory;
}
public static function getDependencies()
{
    return [];
}
public function getAliases()
{
    return [];
}
public function apply()
{
    $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);

    $customerEntity = $customerSetup->getEavConfig()->getEntityType(Customer::ENTITY);
    $attributeSetId = $customerEntity->getDefaultAttributeSetId();

    $attributeSet = $this->attributeSetFactory->create();
    $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);

    $customerSetup->addAttribute(
        Customer::ENTITY,
        'mobile',
        [
            'type' => 'varchar',
            'label' => 'Mobile',
            'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
            'input' => 'text',
            'required' => false,
            'sort_order' => 120,
            'position' => 120,
            'visible' => true,
            'user_defined' => true,
            'system' => false,
            'searchable' => true,
            'is_used_in_grid'   => true,
            'is_visible_in_grid' => true,
            'visible_in_advanced_search' => true,
            'is_searchable_in_grid' => true
        ]
    );
    $attribute = $customerSetup->getEavConfig()->getAttribute(
        Customer::ENTITY,
        'mobile'
    );

    $attribute->addData(
        [
            'attribute_set_id' => $attributeSetId,
            'attribute_group_id' => $attributeGroupId,
            'used_in_forms' => ['adminhtml_customer'],
        ]
    );

    $attribute->save();
}
}

