Laravel & Ecosystem (50 Qs)•Part 3: Octane, High-Throughput Scaling & Enterprise Design (25 - 35)
How does Soft Deleting work in Eloquent?
senior LevellaravelOctane
In Simple Words:
Adds a deleted_at timestamp column to the table:
- When
$user->delete()is called, Eloquent setsdeleted_at = NOW()instead of executing a SQLDELETE. - Automatically injects a Global Scope on all queries:
WHERE deleted_at IS NULL. - Access soft-deleted records via
User::withTrashed()->get()or restore them via$user->restore().