Add the SoftDeletes trait to a model and a deleted_at column to its table, and delete() stops removing rows — it writes a timestamp and Laravel adds where deleted_at is null to every query the model makes:
Author::query() select * from "authors" where "authors"."deleted_at" is null
withTrashed() select * from "authors"
onlyTrashed() select * from "authors" where "authors"."deleted_at" is not null
$author->delete();
Author::count() = 0
Author::withTrashed()->count() = 1
Author::onlyTrashed()->count() = 1
raw row = {"id":1,"email":"ada@example.com","deleted_at":"2026-08-11 16:47:03"}
$author->trashed() = true
restore() nulls the column again, and forceDelete() issues a real DELETE. That much every guide covers, including the previous version of this page. What it did not cover are the two things that break in production, both demonstrated below on a real schema.
Trap 1: a unique index still collides with soft-deleted rows
The database has no idea the row is “deleted”. A unique index on email keeps enforcing itself against the tombstone:
$table->string('email')->unique();
...
$author->delete(); // ada@example.com is now trashed
Author::create(['email' => 'ada@example.com']); // same address signs up again
re-registration FAILED: SQLSTATE[23000]: Integrity constraint violation: 19
UNIQUE constraint failed: authors.email
Users cannot re-register, cannot re-add a deleted SKU, cannot reuse a slug. On SQLite and PostgreSQL the fix is a partial unique index — unique only among live rows:
DB::statement('create unique index authors_email_live on authors (email) where deleted_at is null');
re-registration after soft delete SUCCEEDED
duplicate among live rows still rejected: UNIQUE constraint failed: authors.email
rows total: 2 live: 1
Same behaviour on PostgreSQL 17.10, run directly:
create unique index authors_email_live on authors (email) where deleted_at is null;
INSERT 0 1 -- re-insert after soft delete succeeds
ERROR: duplicate key value violates unique constraint "authors_email_live"
DETAIL: Key (email)=(ada@example.com) already exists. -- second LIVE duplicate still blocked
MySQL has no partial indexes, and the recipe most pages give for it does not work. The widely copied advice is unique(email, deleted_at). On MySQL 8.4.10:
create table t (id int auto_increment primary key, email varchar(191),
deleted_at timestamp null, unique key uq (email, deleted_at));
inserted a SECOND LIVE row with the same email: the index did not stop it
live rows with that email: 2
That composite index is worse than nothing: in SQL, NULL is not equal to NULL, so two live rows (both deleted_at IS NULL) are never seen as duplicates. You end up believing you have uniqueness while having none. A generated column does work on MySQL 8:
live_email varchar(191) generated always as (if(deleted_at is null, email, null)) stored,
unique key uq_live_email (live_email)
second LIVE duplicate rejected: Duplicate entry 'ada@example.com' for key 'uq_live_email'
re-register after soft delete SUCCEEDED
Also add Rule::unique('authors')->whereNull('deleted_at') to your validation, so the user gets a form error rather than a 500 — but validation is not the fix, the index is.
Trap 2: a soft delete cascades nothing
Foreign keys with cascadeOnDelete() fire on DELETE statements. A soft delete is an UPDATE, so nothing downstream happens. The author below has two comments and one pivot row, all declared ->constrained()->cascadeOnDelete():
$author->delete();
rows in comments: 2
Comment::count(): 2 // Comment has no SoftDeletes trait, so they are fully visible
rows in author_tag: 1
Those comments are now orphans pointing at an invisible parent. Every listing that queries Comment directly will show them. Contrast forceDelete(), which does emit a DELETE:
$author->forceDelete();
authors: 0 comments: 0 author_tag: 0
Note the pivot row too: many-to-many pivot rows are plain table rows and a soft delete leaves them attached. If you want children to disappear with the parent, you have to say so — a deleting model event that soft-deletes the children, or a query that filters through the relationship:
protected static function booted(): void
{
static::deleting(function (Author $author) {
if (! $author->isForceDeleting()) {
$author->comments()->delete(); // requires SoftDeletes on Comment too
}
});
}
// or, on the read side:
Comment::whereHas('author')->get(); // excludes comments whose author is trashed
Two smaller things
withTrashed() is not “include deleted” so much as “remove the scope” — the SQL above has no where clause at all. And because the scope is a plain where, it composes with everything else, including whereIn: Author::onlyTrashed()->whereIn('id', $ids) works exactly as you would expect, with the empty-array behaviour described here still applying.
Finally, soft deletes are not an audit log. They record when a row was hidden and nothing else — not who, not why, not what the row looked like before an update. If you need that, you need an audit table; a nullable timestamp is not one.
Check this yourself. Every command and every block of output on this page is reproduced by /verify/laravel-soft-delete-model.sh. Download it and run it: it creates its own scratch files, prints one line per claim, cleans up after itself, and exits non-zero if any claim here turns out to be wrong. If it disagrees with this page, the page is wrong.