Hello Magento Lovers,

I have described how to add toggle (yes/no) attribute to the product using the setup install script.

We always need some features based on enable/disable or yes/no. Magento 2 has introduced a very attractive toggle button.

It's very simple to add using a Script. We can use either Install Data / Upgrade Data file in the setup directory based on our requirement, whether we are creating a module from scratch or we are modifying the existing module.

I have used InstallData.php in this post. 

 app/code/Vendor/Modulename/Setup/InstallData.php

    <?php

namespace Vendor\Module\Setup;

use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

/**
 * Install Data
Read more »