The Problem
Files are harder to delete than rows. When you soft-delete a database record you expect the file to stick around – but when do you actually clean it up? And how do you serve private files without exposing real storage URLs?
Most Laravel apps answer this badly:
Hard-delete the record → orphaned file sits on disk forever
Soft-delete the record → file never moves, “deleted” media is still publicly accessible at its original URL
Schedule a cleanup command → it skips broken records, nobody tests --dry-run , the disk fills up quietly
This article covers the full lifecycle: soft-delete → auto-trash → scheduled prune → secure serving .
Part 1: SoftDeletes with Auto-Trash
The trick is using the model’s deleted event to move the physical file into a trash/ folder the moment the record is soft-deleted. The file is gone from normal access, but recoverable for 30 days.
// app/Models/Media.php <?…