PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, February 9, 2022

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

 February 09, 2022     composer-php, eloquent, laravel-5.7     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

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

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing