spatie/laravel-model-cleanup
Deprecated: use Laravel’s built-in Prunable. Spatie’s laravel-model-cleanup deletes unneeded Eloquent records via a cleanUp() configuration per model, and an artisan command to prune records older than a given age or matching custom rules.
cleanUp() method) for defining cleanup rules, which is intuitive for developers.clean:models Artisan command), reducing database load during execution.prunable trait (introduced in Laravel 9+) renders this package redundant for most use cases.SoftDeletes + prunable).prunable: Laravel’s native solution is more feature-rich (supports dry-run, logging, and scheduled tasks via schedule:run).cleanUp() method and Artisan commands in tests.SoftDeletes + prunable handles this).whereNotIn for related records).prunable?
prunable?prunable incrementally?prunable?prunable dependency).prunable capabilities.cleanUp() methods and their rules.spatie/laravel-model-cleanup for legacy systems with minimal changes.prunable by:
cleanUp() methods with prunable traits.App\Console\Kernel.php) for periodic cleanup.prunable's dry-run and logging features.prunable trait to models and replicate cleanup rules.clean:models Artisan command with schedule:run in a cron job.SoftDeletes, but cleanup targets all records (not just soft-deleted ones).Scopes or Global Scopes in cleanup queries.config/model-cleanup.php.cleanUp() methods for each model.clean:models via cron (e.g., * * * * * php artisan clean:models).prunable within 6–12 months.prunable).config/app.php).chunk() method in custom cleanup logic.cleanUp() method.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Unhandled foreign key constraints | Partial deletes, data corruption | Test in staging; disable constraints temporarily. |
| Large dataset cleanup | Timeouts, locked tables | Use chunk() or queue jobs. |
| Cron job failure | Missed cleanup cycles | Monitor logs; use Laravel’s scheduler. |
| Laravel version incompatibility | Package breaks | Pin package version; migrate to prunable. |
| No rollback mechanism | Accidental data loss | Backup before running cleanup. |
cleanUp() method signature and CleanupConfig options.Log::info("Cleaned up X records")).cleanUp() rules and their business justification.prunable.How can I help you explore Laravel packages today?