New --except Option for Optimize Commands in Laravel 11.38


- Customizing Artisan Commands with the New --except Option in Laravel
- Understanding the Problem
- The New --except Option
- Conclusion
--except
Option in Laravel
Customizing Artisan Commands with the New When managing Laravel applications, the optimize
and optimize:clear
Artisan commands play a crucial role in boosting performance and streamlining deployments. However, these commands have historically lacked flexibility, as they execute all optimization tasks without exception. With the latest improvement in Laravel’s framework (introduced in Pull Request #54070 by Jon Erickson), developers now have greater control over these commands with the addition of the --except
option.
In this post, we’ll explore what this new feature brings to the table and how it solves challenges faced by developers during application optimization.
Understanding the Problem
Laravel’s optimize
and optimize:clear
commands are designed to enhance application performance by caching configurations, routes, views, and events. However, executing all these tasks together isn’t always necessary or desirable as highlighted in php artisan cache:clear - What it DOES and what it does NOT?
article. Previously, there was no built-in way to exclude specific tasks from the optimization process. Developers often resorted to workarounds or manual cache management, adding complexity to deployment pipelines.
--except
Option
The New The --except
option introduces a straightforward and elegant solution to this problem. Available in both the optimize
and optimize:clear
commands, this feature allows developers to exclude specific optimization tasks with a simple flag.
Examples
# skip events and views cachingphp artisan optimize --except=events,views
# skip routes cache clearingphp artisan optimize:clear --except=routes
Laravel Vapor Use Case
In applications deployed on Laravel Vapor, route
caching is unsupported. By leveraging the --except
option, now you can utilize the optimize command without triggering unsupported operations like route:cache
.
Conclusion
The addition of the --except
option to Laravel’s optimize
and optimize:clear
commands is a welcome enhancement that empowers developers to take greater control over application optimization. Whether you’re working on a local development environment or deploying to production, this feature simplifies workflows and ensures a more efficient process.
To start using this feature, make sure you’re running Laravel version 11.28 or higher. For more details, check out the official pull request here.
Happy optimizing!
Stay Updated.
I'll you email you as soon as new, fresh content is published.