Laravel Cleanup Data: Data Retention as a Policy, Not Scattered Cron Jobs
Define retention rules once, preview with a dry run, and anonymize or delete on a schedule with a safety cap that aborts mass deletes.

Overview
Old logs, exports, and temp files pile up, and prune scripts end up scattered across Artisan commands, cron jobs, and one-off queries. I got tired of seeing that in every Laravel app I maintained, so I built Laravel Cleanup Data to put retention rules in one place.
You define a rule once, preview it with a dry run, and let it run on a schedule:
// Preview first, nothing is touched
Cleaner::model(ActivityLog::class)->days(30)->dryRun();
// Then run it
Cleaner::model(ActivityLog::class)->days(30)->clean();
What it covers
Laravel Cleanup Data handles the full retention lifecycle:
- Delete or anonymize old records with built-in strategies: hashed emails, masked values, nullification, and fixed replacements.
- Dry run on every cleanup, so you see what would be affected before anything is deleted.
- A
max_affectedcap that aborts the run before any changes if too many rows match. This protects you from a bad query deleting half a table. - Anonymization that runs once per record, using an
anonymized_atmarker. - An audit log of each run, with counts and samples.
- Custom cleaners for files, exports, and other non-model data.
Safety first: The max_affected cap is the key feature. If a retention rule suddenly matches more rows than expected, the run aborts before any changes — no accidental mass deletes.
When to use it
If you only need to delete old rows from a few models, Laravel’s own Prunable is the simpler choice.
This package is for when retention becomes a policy: dry runs, anonymization, safety caps, and audit logs. It’s built for apps where data retention is a compliance requirement, not just a housekeeping task.
Why it matters
Data retention isn’t just about disk space. GDPR, HIPAA, and other regulations require you to handle old data responsibly — not just delete it, but sometimes anonymize it, log what you did, and be able to prove it.
Laravel Cleanup Data turns retention from a scattered set of cron jobs into a documented, auditable policy. You can see what each run did, review samples, and sleep better knowing a bad rule won’t wipe your production database.
Current version
Current version is 1.1.7. It needs PHP 8.4+ and Laravel 12 or 13, and it’s MIT licensed.
Docs and install
- Docs: https://tyhuynh.id.vn/libraries/laravel-cleanup-data/
- GitHub: https://github.com/T-Labs-Co/laravel-cleanup-data
Support
If it saves you time, a coffee here helps keep it maintained.
More packages: https://tyhuynh.id.vn/libraries
Legal Notice
This is an independently written summary and technical commentary. Original reporting belongs to its respective author and publisher. All trademarks belong to their respective owners.
For copyright or takedown requests, contact hongty.huynh@gmail.com or visit the Legal Disclaimer page.