How to Drop Soft Delete from Table in Laravel Migration?

Jan 25, 2023

.

Admin

How to Drop Soft Delete from Table in Laravel Migration?

Hi dev,

This tutorial will cover the Laravel Drop Soft Delete Migration demonstration. The specifics of dropping soft delete from a table in a Laravel migration are covered in this post. You will be given a straightforward example of laravel remove soft delete migration in this article. The idea of laravel migration remove soft delete is understandable.

Laravel provides the dropSoftDeletes() function to remove soft delete from the table if you wish to drop soft delete from the table via migration.

Soft deletion essentially uses the deleted at column. You must take that away. The solution and complete migration example are shown below.

Solution:


Schema::table('posts', function(Blueprint $table)

{

$table->dropSoftDeletes();

});

Example:

let's create new migration using following command:

php artisan make:migration add_soft_delete_posts

next, updated migration file as like the below:

database/migrations/2023_01_16_134448_add_soft_delete_posts.php

<?php

use Illuminate\Database\Migrations\Migration;

use Illuminate\Database\Schema\Blueprint;

use Illuminate\Support\Facades\Schema;

return new class extends Migration

{

/**

* Run the migrations.

*

* @return void

*/

public function up()

{

Schema::table('posts', function(Blueprint $table)

{

$table->softDeletes();

});

}

/**

* Reverse the migrations.

*

* @return void

*/

public function down()

{

Schema::table('posts', function(Blueprint $table)

{

$table->dropSoftDeletes();

});

}

};

Now, you can run migration:

php artisan migrate

I hope it can help you...

#Laravel