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
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial