Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Model Cleanup Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Database Maintenance Automation: Reduces manual cleanup tasks for stale or obsolete records, improving operational efficiency.
  • Cost Optimization: Automatically prunes unnecessary data to reduce storage costs, especially for SaaS or high-volume applications.
  • Compliance & Retention Policies: Enables enforcement of data retention rules (e.g., GDPR, HIPAA) by systematically purging outdated records.
  • Legacy System Migration: Useful for phasing out deprecated features or old data during platform transitions.
  • Build vs. Buy: Avoids reinventing a cleanup solution, leveraging a lightweight, open-source alternative (though now deprecated in favor of Laravel’s built-in prunable).
  • Feature Roadmap: Supports long-term scalability by integrating cleanup logic directly into model definitions, reducing technical debt.

When to Consider This Package

  • Adoption Criteria:

    • Your team is already using Laravel and needs a simple, declarative way to manage record cleanup.
    • You require time-based pruning (e.g., "delete records older than X days") without complex logic.
    • The package’s MIT license aligns with your open-source policy, and you’re okay with minimal maintenance overhead.
    • You’re not using Laravel 8+, where the built-in prunable trait is the recommended alternative.
  • Look Elsewhere If:

    • You need active maintenance or advanced features (e.g., conditional cleanup, soft deletes, or event triggers).
    • Your cleanup logic requires custom SQL, batch processing, or async operations (consider laravel-scheduler + custom jobs).
    • You’re using Laravel 8+, where prunable is the official, maintained solution.
    • Compliance requires audit logs or dry-run capabilities (this package lacks those; evaluate alternatives like spatie/laravel-activitylog + custom logic).

How to Pitch It (Stakeholders)

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:

  • Quick wins: No need to build a custom scheduler or cron job.
  • Consistency: Enforces cleanup logic across all models in a standardized way.
  • Legacy systems: Works well if we’re not yet on Laravel 8+. Tradeoff: It’s archived, so we’d need to monitor for edge cases or plan a migration to 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:

  • No soft deletes: Records are hard-deleted.
  • No events: Can’t trigger actions before/after cleanup.
  • Deprecated: Laravel 8+ has 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."*
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport