How to Drop Soft Delete from Table using Migration in LARAVEL?

Spread the love

Hello, Guys

This tutorial provides a comprehensive guide on how to “Drop Soft Delete” in Laravel using migrations. We will walk you through the steps to remove soft delete functionality from a table in Laravel using migrations in this post. You’ll find a clear and practical example of how to perform a Laravel soft delete removal migration in this article. The concept of removing soft delete functionality through Laravel migrations will be explained in a straightforward manner.

In Laravel, you can easily eliminate soft delete functionality from a table using the dropSoftDeletes() function within a migration.

Soft deletion in Laravel primarily relies on the ‘deleted‘ column, and we will demonstrate how to remove it. Below, you’ll find the solution and a complete example of the migration process.

Laravel Drop Soft Delete Using Migration:

Also Read: How to Create Custom Artisan Command in LARAVEL

Solution:

Schema::table('posts', function(Blueprint $table)
{
    $table->dropSoftDeletes();
});

Example:

Create a fresh migration using the following command:

php artisan make:migration add_soft_delete_posts

Next, an enhanced migration file, akin to the example below:

Also Read: How to Use LARAVEL DB Raw Query?

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();
        });
    }
};

You can initiate the migration process now:

Also Read: How to use laravel cookies – Get, Set, Delete with example

php artisan migrate

Embrace the elite realm of Laravel insights – your compass to the best Laravel blog awaits.

Leave a Comment