ItSolutionStuff.com

How to Drop Soft Delete from Table using Laravel Migration?

By Hardik Savani • November 5, 2023
Laravel

Hi Artisan,

In this tutorial, we will go over the demonstration of laravel drop soft delete migration. This article goes in detailed on how to drop soft delete from table in laravel migration. This article will give you a simple example of laravel remove soft delete migration. you can understand a concept of laravel migration remove soft delete.

If you want to drop soft delete from the table using migration then laravel provides dropSoftDeletes() function to remove soft delete from the table.

Basically, soft delete work with deleted_at column. You need to remove that. You can see the below solution with a full migration example.

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...

Tags: Laravel
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Laravel Migration Default Value Current Timestamp Example

Read Now →

How to Create Migration in Laravel 9?

Read Now →

How to Run Migration and Seeder on Laravel Vapor?

Read Now →

How to Change Column Length using Laravel Migration?

Read Now →

How to Update Enum Value in Laravel Migration?

Read Now →

Laravel Migration Enum Default Value Example

Read Now →

Laravel Migration Add Enum Column Example

Read Now →

How to Rollback Migration in Laravel?

Read Now →

Laravel Migration Add Comment to Column Example

Read Now →

How to Add Index in Laravel Migration?

Read Now →

How to Change Table Name using Laravel Migration?

Read Now →

How to Remove Column from Table in Laravel Migration?

Read Now →

How to Change Column Name and Data Type in Laravel Migration?

Read Now →

How to Create Table using Migration in Laravel?

Read Now →