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 Cleaner Laravel Package

vizrex/laravel-cleaner

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation:

    composer require vizrex/laravel-cleaner
    

    Publish the config (if needed) with:

    php artisan vendor:publish --provider="Vizrex\Cleaner\CleanerServiceProvider"
    
  2. First Use Case: Run a basic cleanup for all registered commands:

    php artisan app:cleanup --all
    

    Verify the output to confirm which commands were executed (e.g., cache:clear, session:clear).

  3. Key Files:

    • Config: config/cleaner.php (if published) – Customize excluded files/directories.
    • Commands: app/Console/Kernel.php – Check if the CleanerCommand is registered (it should be by default).

Implementation Patterns

Core Workflows

  1. Targeted Cleanup: Use flags to selectively clear specific caches or logs:

    php artisan app:cleanup --log --session
    

    Ideal for CI/CD pipelines or post-deployment cleanup.

  2. Scheduled Cleanup: Add a cron job or Laravel scheduler task (e.g., app/Console/Kernel.php) to run periodically:

    $schedule->command('app:cleanup --log --session')->daily();
    

    Useful for automated maintenance (e.g., clearing old logs weekly).

  3. Custom Exclusions: Extend the package by modifying config/cleaner.php to exclude sensitive files:

    'excludes' => [
        'storage/framework/sessions/*_important_session*',
    ],
    
  4. Integration with Deployments: Trigger cleanup post-deploy in deploy.php (Deployer) or afterDeploy hook (Envoyer):

    run('php artisan app:cleanup --all');
    

Pro Tips

  • Combine with env:switch: Clear caches/logs when switching environments:
    php artisan env:switch production && php artisan app:cleanup --all
    
  • Logging Cleanup: Redirect output to a log file for auditing:
    php artisan app:cleanup --log > cleanup.log
    

Gotchas and Tips

Pitfalls

  1. Permission Issues:

    • Ensure the Laravel storage directory (storage/) has writable permissions for the web server user (e.g., chmod -R 775 storage/).
    • Debug: Run with --verbose to identify permission errors:
      php artisan app:cleanup --log --verbose
      
  2. Partial Cleanup:

    • The --all flag runs all registered commands, including third-party ones (e.g., debugbar:clear). Test in a staging environment first.
    • Fix: Use explicit flags (e.g., --log --session) to avoid unintended side effects.
  3. Log Rotation:

    • log:clear deletes all laravel*.log files. For production, consider:
      • Using Laravel’s built-in log rotation (LOG_MAX_FILES in .env).
      • Implementing a custom log retention policy before using this command.
  4. Session Data Loss:

    • session:clear deletes all session files. Avoid running this in production during active user sessions unless necessary.

Debugging

  • Dry Run: Add --dry-run (if supported in future updates) or manually check the storage/framework/sessions/ and storage/logs/ directories before running cleanup.

  • Command Registration: If a command (e.g., debugbar:clear) fails silently, verify it’s registered in app/Console/Kernel.php:

    protected $commands = [
        \Barryvdh\Debugbar\Console\ClearCommand::class, // Example for Debugbar
    ];
    

Extension Points

  1. Custom Commands: Extend the package by adding new cleanup commands. Example:

    // app/Console/Commands/CustomCleanup.php
    use Vizrex\Cleaner\Traits\CleanupTrait;
    
    class CustomCleanup extends Command {
        use CleanupTrait;
    
        protected $signature = 'custom:clean';
        public function handle() {
            $this->cleanDirectory(storage_path('app/custom_cache'));
        }
    }
    
  2. Pre/Post Hooks: Override the CleanerCommand to add logic before/after cleanup:

    // app/Console/Commands/CleanerCommand.php
    protected function execute(Input $input, Output $output) {
        $this->info('Starting cleanup...');
        parent::execute($input, $output);
        $this->info('Cleanup complete.');
    }
    
  3. Config Overrides: Dynamically set exclusions via environment variables:

    // config/cleaner.php
    'excludes' => env('CLEANER_EXCLUDES', []),
    

    Then run:

    CLEANER_EXCLUDES="storage/framework/sessions/*_admin*" php artisan app:cleanup --session
    
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.
nasirkhan/laravel-sharekit
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony