🎉🎉 Larasense is officially launched 🎉🎉
- Your Hub for Laravel News, Trends & Updates

New --except Option for Optimize Commands in Laravel 11.38

laravel
release
optimize
Nabil Hassen
Nabil Hassen
Jan 16, 2025
--except Option for Optimize commands
Last updated on Jan 17, 2025
Table of contents:

Customizing Artisan Commands with the New --except Option in Laravel

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.

The New --except Option

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 caching
php artisan optimize --except=events,views
# skip routes cache clearing
php 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!

Nabil Hassen
Nabil Hassen
Full Stack Web Developer

Stay Updated.

I'll you email you as soon as new, fresh content is published.

Thanks for subscribing to my blog.

Latest Posts

Larasenes Logo
Larasense
Stay updated on Laravel news, trends, and updates with curated content from top blogs, YouTube, and podcasts in a sleek, user-friendly design.