52

I'm adding the soft delete columns to my table in a migration:

public function up()
{
    Schema::table("users", function ($table) {
        $table->softDeletes();
    });
}

But, how can I remove these in my down() function, if I roll back the migration? Is there a built-in method to do this, or do I just manually delete the columns that get added?

miken32
  • 42,008
  • 16
  • 111
  • 154

1 Answers1

112

On your migration class use dropSoftDeletes():

public function down()
{
    Schema::table("users", function ($table) {
        $table->dropSoftDeletes();
    });
}

This method can be found in Illuminate\Database\Schema\Blueprint.php:

public function dropSoftDeletes()
{
    $this->dropColumn('deleted_at');
}

Since Laravel 5.5, this information can be found in the documentation.

miken32
  • 42,008
  • 16
  • 111
  • 154
Álvaro Guimarães
  • 2,154
  • 2
  • 16
  • 24
  • Thanks; is there any actual API documentation that you used to find this? I'm using the docs at https://laravel.com/docs/5.2 which gives a good overview, but doesn't list every available method. – miken32 May 30 '16 at 19:29
  • 3
    You better navigate through the core classes. The documentation is always lacking some sugar. – Álvaro Guimarães May 30 '16 at 19:32
  • 7
    OMG, after dropSoftDeletes - we are going to have a mess of historical and actual records together... – Yevgeniy Afanasyev Oct 27 '16 at 22:10
  • Updating Laravel framework files is not a good move?! What about updates, etc? – Jquestions Dec 13 '18 at 19:36
  • dropSoftDeletes() already exists in Illuminate\Database\Schema\Blueprint.php (at least as of Laravel 8.12) so no updating of framework files is necessary. – Elijah Lofgren Dec 17 '20 at 19:32
  • 1
    They were always there, just not in the docs. And I never suggested editing framework files, please don't do it @Jquestions – Álvaro Guimarães Dec 31 '20 at 12:21