Wednesday, February 9, 2022

[FIXED] delete column from table when deleted package in laravel

Issue

When a field in the database is added by installing a package, how do I make sure that it is removed when I uninstall the package. Will it be deleted?


Solution

Many Laravel packages come with migrations that create tables (and fields at times) like this:

public function up()
{
    Schema::create($this->getTableName(), function (Blueprint $table) {
        $table->increments('id');
        $table->string('first_name');
        $table->string('last_name');
        $table->string('email');
        $table->timestamps();
    });
}

and usually, remove them on tear down

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::dropIfExists($this->getTableName());
}

However, sometimes things go wrong and you may want to check yourself. Refer the database/migrations file that shipped with the package and see what was created and compare it to the tables/columns you see in your database.



Answered By - wp78de

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.