MWZ

MINDWAREZONE

intermediateLaravel

What are soft deletes?

Answer

Clear, interview-ready explanation

Soft deletes mark a record as deleted by setting its deleted_at timestamp instead of removing the row from the database. A model uses the SoftDeletes trait and its table needs a nullable deleted_at column, commonly added with the softDeletes migration method.

Eloquent automatically excludes soft-deleted models from normal queries. withTrashed includes them, onlyTrashed selects only deleted records, restore reverses the soft deletion, and forceDelete permanently removes a record. Soft deletes support recovery and audit needs, but related data, unique constraints, retention policies, and privacy obligations still require deliberate design.