Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to drop softDeletes from a table in a migration

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?

like image 671
miken32 Avatar asked May 30 '16 18:05

miken32


People also ask

What is the use of soft delete in laravel?

Soft deleting the data allows us to easily view and restore the data with minimal work and can be a huge time saver when data is accidentally deleted. Laravel provides support for soft deleting using the Illuminate\Database\Eloquent\SoftDeletes trait.


1 Answers

On your migration class:

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

Illuminate\Database\Schema\Blueprint.php:

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

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

like image 183
Álvaro Guimarães Avatar answered Sep 18 '22 21:09

Álvaro Guimarães