Migration: Removing field from GlobalSet/Entry Im creating my own migrations to better handle adding/removing fields on all environments.

Is the following safeDown() function the correct way to remove a field from a fieldlayout? It works but im open if their is a better way to archive this.

  public function safeDown()
{
    $tabStructure = [];
    $cartDestinationUrl = Craft::$app-&gt;fields-&gt;getFieldByHandle('cartDestinationUrl');
    $headerGlobalSet = Craft::$app-&gt;globals-&gt;getSetByHandle('header');
    $tabs = $headerGlobalSet-&gt;getFieldLayout()-&gt;getTabs();

    foreach ($tabs as $tab) {
        $fields = $tab-&gt;getFields();
        $fieldIds = [];
        foreach ($fields as $field) {
            $fieldId = $field-&gt;id;
            if ($fieldId !== $cartDestinationUrl-&gt;id) {
                $fieldIds[] = $fieldId;
            }
        }
        $tabStructure[$tab-&gt;name] = $fieldIds;
    }

    //remove empty tabs from layout 
    $tabStructure = array_filter($tabStructure);

    $globalSetLayout = Craft::$app-&gt;fields-&gt;assembleLayout($tabStructure);
    $headerGlobalSet-&gt;setFieldLayout($globalSetLayout);

    return (Craft::$app-&gt;globals-&gt;saveSet($headerGlobalSet));
}
Did you consider using Craft 3.1 new Project Config File feature?

https://docs.craftcms.com/v3/project-config.html#enabling-the-project-config-file

Any time a field is added, modified ou removed, every environment will be updated to match the primary one. That could be much more easier than handling it manually with migrations.