What are Soft Deletes in Eloquent?
Why Interviewers Ask This
This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex Laravel topics. It also reveals how well you can explain technical ideas to non-experts.
Answer
Soft deletes allow you to "delete" records without actually removing them from the database — a deleted_at timestamp is set instead. To enable: add use SoftDeletes; trait to the model and add a $table->softDeletes() column to the migration. When you call $user->delete(), the deleted_at field is set to the current timestamp. Normal queries automatically filter out soft-deleted records. Include soft-deleted records: User::withTrashed()->get(). Only soft-deleted: User::onlyTrashed()->get(). Restore: $user->restore(). Permanently delete: $user->forceDelete(). Soft deletes are useful for audit trails, accidental deletion recovery, and "trash" features. The deleted_at column must be nullable.
Common Mistake
Rushing to answer is a common mistake. Take two seconds to structure your response: definition → example → trade-off. This structure makes complex Laravel answers easy to follow.