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.
prunable).Adoption Criteria:
prunable trait is the recommended alternative.Look Elsewhere If:
laravel-scheduler + custom jobs).prunable is the official, maintained solution.spatie/laravel-activitylog + custom logic).For Executives:
"This package automates the cleanup of stale database records—like old logs, expired subscriptions, or temporary data—reducing storage costs and manual maintenance. It’s a lightweight, one-time setup that integrates seamlessly with Laravel, saving dev time and ensuring compliance with data retention policies. While not actively maintained, it’s a proven solution for teams already using Laravel 7 or earlier. For newer versions, we can migrate to Laravel’s built-in prunable trait with minimal effort."
For Engineering:
*"The spatie/laravel-model-cleanup package lets us define cleanup rules directly in Eloquent models (e.g., olderThanDays(5)), then trigger purges via an Artisan command. It’s ideal for:
prunable later. For complex needs (e.g., conditional deletes), we’d pair it with custom logic or consider alternatives like laravel-scheduler."*For Developers:
*"This package lets you add a cleanUp() method to any model to define how old records should be deleted. For example:
public function cleanUp(CleanupConfig $config) {
$config->olderThanDays(30); // Deletes records >30 days old
}
Then run php artisan clean:models to execute. It’s simple, but note:
prunable, which is more feature-rich.
Use case: Perfect for disposable data (e.g., drafts, cache, or temporary uploads). For critical data, validate the logic or extend it."*How can I help you explore Laravel packages today?