Removing Soft Delete from Laravel Table with Migration
In this post we will give you information about Removing Soft Delete from Laravel Table with Migration. Hear we will give you detail about Removing Soft Delete from Laravel Table with Migration And how to use it also give you demo for it if it is necessary.
This article explains how to get rid of the “soft delete” functionality from a table in Laravel using migrations. In Laravel, soft delete means marking data as deleted in the database instead of actually deleting it. However, sometimes this feature may not be required, and it can be removed from the table. The tutorial will walk you through the steps of removing soft delete from a Laravel table using migrations in a clear and organized way.
If you want to drop soft delete from the table using migration, then laravel provides the dropSoftDeletes()
function to remove soft delete from the table.
Soft delete work with deleted_at
column. You need to remove that. You can see the below solution with a complete migration example.
Solution:
Schema::table('posts', function(Blueprint $table){
$table->dropSoftDeletes();
});
Example:
Create new migration, run the following command:
php artisan make:migration add_soft_delete_posts
Next, update your migration file to match the following:
database/migrations/2023_02_02_135632_add_soft_delete_posts.php
<?php
use IlluminateDatabaseMigrationsMigration;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateSupportFacadesSchema;
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 the migration:
php artisan migrate
Conclusion
In conclusion, removing the soft delete feature from a Laravel table is a straightforward process that can be achieved through migrations. By following the steps outlined in this article, you can effectively remove the soft delete functionality from your Laravel application and modify the database structure accordingly. Whether you no longer need the soft delete feature or simply want to streamline your application, this tutorial provides a clear and easy-to-follow guide for removing soft delete from a Laravel table using migrations.
Thank you for reading Removing Soft Delete from Laravel Table with Migration . Hope this code and post will helped you for implement Removing Soft Delete from Laravel Table with Migration. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs