Manamil Dev Logo
Facebook Icon X Icon Linkedin Icon

Muhammad Manamil on January 19, 2026

Soft Deletes vs Permanent Deletes in Laravel | Complete Guide with Examples

Soft Deletes vs Permanent Deletes in Laravel | Complete Guide with Examples
Share on X Share on Facebook Share on LinkedIn

Laravel is a popular PHP framework that provides a clean and elegant syntax for web development. One of the most important aspects of managing database records in Laravel is deleting data. But did you know Laravel provides two types of deletion?

  1. Soft Deletes – Temporarily delete a record without removing it from the database.

  2. Permanent Deletes – Permanently remove a record from the database.

Understanding the difference is crucial for data management, auditing, and recovery in real-world applications.

Soft Deletes in Laravel

Soft deletes allow you to mark a record as deleted without actually removing it from the database. This is useful when you want to keep a record for recovery or auditing purposes.

How Soft Deletes Work

When you enable soft deletes in a model, Laravel adds a deleted_at timestamp column. If this column is null, the record is considered active; if it has a timestamp, it is considered deleted.

Example

  1. Migration
    Add soft deletes to your table using the softDeletes() method:

    use Illuminate\Database\Migrations\Migration;
    use Illuminate\Database\Schema\Blueprint;
    use Illuminate\Support\Facades\Schema;

    class CreatePostsTable extends Migration
    {
        public function up()
        {
            Schema::create('posts', function (Blueprint $table) {
                $table->id();
                $table->string('title');
                $table->text('content');
                $table->timestamps();
                $table->softDeletes(); // Adds deleted_at column
            });
        }

        public function down()
        {
            Schema::dropIfExists('posts');
        }
    }

  2. Model Setup
    
    

    use Illuminate\Database\Eloquent\Model;
    use Illuminate\Database\Eloquent\SoftDeletes;

    class Post extends Model
    {
        use SoftDeletes; // Enable soft deletes
    }

  3. Usage
    
    

    // Soft delete a record
    $post = Post::find(1);
    $post->delete(); // Sets deleted_at timestamp

    // Retrieve all posts including soft deleted
    $allPosts = Post::withTrashed()->get();

    // Retrieve only soft deleted posts
    $deletedPosts = Post::onlyTrashed()->get();

    // Restore soft deleted post
    $post->restore();

Benefits of Soft Deletes

  • Allows recovery of accidentally deleted records.

  • Keeps historical data for auditing.

  • Doesn’t permanently lose important information.

Permanent Deletes in Laravel

Permanent deletes, as the name suggests, remove records completely from the database. Once deleted, the data cannot be recovered (unless you have a backup).

// Permanent delete a record
$post = Post::find(1);
$post->forceDelete(); // Completely removes record from DB

Or, without soft deletes enabled:

$post = Post::find(1);
$post->delete(); // Deletes record permanently

When to Use Permanent Deletes

  • Removing temporary test data.

  • Deleting records that are no longer needed for business or legal purposes.

  • Freeing up storage space in large databases.

Key Differences Between Soft Deletes and Permanent Deletes

Feature Soft Deletes Permanent Deletes
Data Removal Marks deleted_at timestamp; record remains in DB Completely removes record from DB
Recovery Can restore deleted records Cannot restore deleted records
Use Case Auditing, accidental deletion recovery Permanent cleanup or obsolete data removal
Querying Use withTrashed() or onlyTrashed() to include soft deleted Only active records exist; deleted records gone

Soft deletes are great for safety and auditing, while permanent deletes are better for cleaning up unnecessary data. Using the right deletion method helps maintain a clean, reliable database in Laravel applications.

1. What is the difference between soft deletes and permanent deletes in Laravel?

  • Soft Deletes: Marks a record as deleted by setting a deleted_at timestamp but keeps it in the database. You can restore it later.

  • Permanent Deletes: Completely removes the record from the database. Recovery is not possible unless you have a backup.

2. How do I enable soft deletes in Laravel?

  • Add the softDeletes() method in your migration to create the deleted_at column.

  • Use the SoftDeletes trait in your Eloquent model.

3. How can I retrieve soft-deleted records?

  • Use withTrashed() to retrieve all records including soft-deleted ones.

  • Use onlyTrashed() to retrieve only soft-deleted records.

4. How can I restore a soft-deleted record?

$post = Post::withTrashed()->find(1);
$post->restore();

5. When should I use soft deletes?

  • To prevent accidental data loss.

  • To maintain historical records for auditing.

  • When you may need to recover deleted data in the future.

6. How do I permanently delete a record?

  • If soft deletes are enabled:

    $post->forceDelete(); // permanently deletes the record

  • If soft deletes are not enabled:
    $post->delete(); // permanently deletes the record

7. When should I use permanent deletes?

  • Removing temporary or test data.

  • Deleting records that are no longer needed for business or legal reasons.

  • Freeing up storage space in large databases.

8. Can soft-deleted records still affect queries?

  • No, by default soft-deleted records are excluded from queries.

  • To include them, use withTrashed().

9. Does soft deleting a record free up database space?

  • No. The record still exists in the database; it only gets marked as deleted.

10. Can I mix soft deletes and permanent deletes in the same application?

  • Yes. You can soft delete most records and permanently delete others using forceDelete() whenever needed.

Featured Posts

Read Next

November 10 2025

Laravel 12 Social & Passkey Authentication (AuthKit) – Complete Guide

Authentication is one of the most important parts of any modern web app — and Laravel 12 makes it easier than ever with AuthKit, which supports social logins (like Google, GitHub, Facebook) and passkey authentication (passwordless login using Face ID, Touch ID, or security keys). In this guide, you’ll learn step-by-step how to set up Social Login + Passkey Authentication in Laravel 12 using AuthKit — from scratch.

November 26 2025

DNS Checker Guide: Tools, Online Services, and Email Check

Discover the best DNS checker tools and online services for Google DNS, global DNS, website DNS, email DNS, and more. Learn how to check IPs, reverse lookup, blacklists, and email headers with ease

December 01 2025

How to Check Your Domain's IP Address | Easy Step-by-Step Guide

Learn how to quickly check the IP address of your domain using methods for Ubuntu, Mac, and online DNS tools. Whether you're troubleshooting, securing your website, or configuring DNS settings, this guide provides simple, actionable steps to find your domain's IP with ease.

Design Circle Design Circle
Manamil Dev Logo

Where ideas meet innovation. Exploring tech, design, and creativity in every line of code.

© 2026 — Revision. All Rights Reserved.