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 Directory Cleanup Laravel Package

spatie/laravel-directory-cleanup

Automatically delete old files from specified directories in Laravel. Configure per-path age limits (in minutes) via a published config file, then run cleanup to keep temp, cache, and upload folders tidy. Supports auto service provider registration in Laravel 5.5+.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Cost Efficiency & Maintenance Reduction: Eliminates manual cron jobs or custom scripts for file cleanup, reducing DevOps overhead and operational costs.
  • Scalability: Automates cleanup of temporary files (e.g., uploads, logs, cache) to prevent storage bloat, critical for SaaS platforms with variable user activity.
  • Compliance & Security: Enforces retention policies (e.g., GDPR, HIPAA) by systematically purging outdated files (e.g., user uploads, session data) without manual intervention.
  • Feature Roadmap Alignment:
    • Build vs. Buy: Avoid reinventing wheel for a common need; leverages battle-tested open-source.
    • Migrations: Simplifies cleanup during data migrations (e.g., archiving old records).
    • Performance: Reduces storage costs and improves app speed by trimming unused files (e.g., storage/app/public for media libraries).
  • Use Cases:
    • Media Libraries: Auto-delete thumbnails/attachments older than X days.
    • Logs/Backups: Rotate logs or purge backups older than a threshold.
    • Session Data: Clean up expired user sessions in storage/framework/sessions.
    • Temporary Files: Clear /tmp or storage/framework/cache directories.

When to Consider This Package

Adopt if:

  • Your Laravel app stores time-sensitive files (uploads, logs, cache) that need automated cleanup.
  • You lack dedicated DevOps resources to manage cron jobs or custom cleanup scripts.
  • Compliance requires strict file retention policies (e.g., "delete user uploads after 30 days").
  • You’re using shared hosting with limited cron access or need a lightweight solution.

Look elsewhere if:

  • You need granular control (e.g., per-file metadata-based deletion) beyond age-based rules.
  • Your cleanup logic requires complex business rules (e.g., "delete files only if related database records are purged").
  • You’re already using a dedicated storage service (e.g., S3) with built-in lifecycle policies.
  • Your team prefers custom solutions for tighter integration with existing workflows (e.g., event-driven cleanup).

How to Pitch It (Stakeholders)

For Executives: "This package automates the cleanup of old files in our Laravel app—think uploads, logs, or cache—saving storage costs and reducing manual maintenance. For example, if we’re storing user-generated content, it’ll delete files older than 30 days without lifting a finger. It’s like setting a ‘self-cleaning’ mode for our storage, cutting DevOps overhead and ensuring compliance with data retention policies. Low-risk (MIT license), high-reward: minimal effort, immediate cost savings."

For Engineering: *"Spatie’s laravel-directory-cleanup is a lightweight, configurable way to handle file expiration via Laravel’s scheduler. Key benefits:

  • Zero cron management: Integrates with Laravel’s task scheduling.
  • Flexible config: Define retention rules per directory (e.g., storage/app/public → 90 days).
  • Safe defaults: Dry-run mode and logging to avoid accidental deletions.
  • Open-source: Actively maintained (last release Feb 2026), with clear docs. Use case: Replace ad-hoc scripts for purging old uploads or logs. Example config:
[
    'directories' => [
        'storage/app/public' => '90 days',
        'storage/logs' => '30 days',
    ],
]

Proposal: Add to our composer.json and schedule the cleanup task in app/Console/Kernel.php. Estimated effort: 1 hour for setup, ongoing savings in storage and DevOps time."*

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