modules:clear command removes the cached module registry, forcing Laravel to rescan and rediscover all modules on the next request.
Usage
What It Does
- Deletes cache file - Removes
bootstrap/cache/modules.phpif it exists - Resets in-memory data - Clears the plugin data repository
- Forces rediscovery - Next request will scan modules directory
- Confirms success - Displays a success message
Example Output
When to Use
Runmodules:clear whenever you make changes to module structure or configuration:
After Module Changes
Added a new module:During Development
Clear cache when:- Module namespaces aren’t resolving correctly
- New service providers aren’t being discovered
- Module routes or views aren’t loading
- Debugging module-related issues
Before Caching
Themodules:cache command automatically calls modules:clear first, but you can run it manually:
Development Workflow
Typical development workflow with modules:What Gets Cleared
Cache File
Removesbootstrap/cache/modules.php which contains:
- Module paths and namespaces
- Autoload configuration
- Service provider mappings
- Module metadata
Runtime Data
Resets the in-memory plugin data repository, ensuring:- No stale module references
- Fresh module scanning on next request
- Clean state for testing
Cache vs Clear
Understanding when to use each command:| Command | Purpose | Environment | Effect |
|---|---|---|---|
modules:cache | Store module data | Production | Creates cache file |
modules:clear | Remove module data | Development | Deletes cache file |
In development environments, you typically keep the cache clear to allow automatic module discovery. In production, you always want the cache enabled for performance.
Automatic Cache Clearing
Some commands automatically clear the module cache:make:module
Creating a new module automatically clears cache:modules:cache
Caching modules automatically clears stale cache first:Troubleshooting
Module changes not taking effect?
Problem: Modified module configuration isn’t being recognized. Solution: Clear the module cache:New module not showing in modules:list?
Problem: Just created a module but it doesn’t appear. Solution:Service provider not loading?
Problem: Module service provider isn’t being discovered. Solution:Cache file won’t delete?
Problem: Permission denied when clearing cache. Solution: Check file permissions:Integration with Development Tools
File Watchers
Automatically clear cache when module files change:IDE Scripts
Create a run configuration in PhpStorm:- Name: Clear Module Cache
- Command:
modules:clear - Shortcut: Assign keyboard shortcut for quick access
Git Hooks
Clear cache after pulling changes:Best Practices
Development Environment
- Don’t cache modules during active development
- Clear cache after composer updates
- Clear cache when switching branches
- Clear cache before debugging module issues
CI/CD Pipelines
Include cache clearing in test setup:Production Deployments
During deployment:Related Commands
- modules:cache - Create module cache for production
- modules:list - Verify modules after clearing cache
- make:module - Create new module (auto-clears cache)
- modules:sync - Update configuration after clearing cache