如何在 Laravel 迁移中删除“变形”列

par*_*ing 1 laravel eloquent laravel-migrations

我正在编辑一个表,以便它使用多态关系:

public function up()
    {
        Schema::table('locations', function (Blueprint $table) {
            $table->morphs('location');
        });
    }
Run Code Online (Sandbox Code Playgroud)

但我不知道最好的方法来扭转这种迁移。我是否必须删除它创建的两列和索引本身,或者有没有办法在 Laravel 的一行中执行此操作?谢谢。

Jef*_*eff 9

Blueprintapi中找到了这个:

public function dropMorphs($name, $indexName = null)
{
    $this->dropIndex($indexName ?: $this->createIndexName('index', ["{$name}_type", "{$name}_id"]));

    $this->dropColumn("{$name}_type", "{$name}_id");
}
Run Code Online (Sandbox Code Playgroud)

所以就 $table->dropMorphs('location');