Laravel 12.39: @hasStack Directive, Route Filtering & Performance Boosts

Laravel 12.39 brings focused improvements that enhance developer experience without breaking anything. The standout additions are the @hasStack Blade directive, middleware filtering for route:list, and a set of type safety and testing fixes that matter in production.

What's New in Laravel 12.39

  • @hasStack Blade Directive — Conditional stack rendering
  • Route List Middleware Filtering — Filter routes by middleware from the CLI
  • Type Safety Enhancements — Better PHP type hints across the framework
  • Parallel Test Support — WithCachedConfig now works with parallel testing
  • Symfony 7.4 Compatibility — Updated Request::getAcceptableContentTypes()

1. @hasStack Blade Directive

The new @hasStack directive lets you conditionally render wrapper elements only when a Blade stack has content. Before this, stacks could leave behind empty <div> or <script> wrappers even when nothing was pushed to them.

@push('scripts') <script>console.log('Custom script');</script> @endpush @hasstack('scripts') <script src="https://cdn.example.com/app.js"></script> @stack('scripts') @endif

This ensures the CDN script tag only renders when the stack actually has content — cleaner HTML, no wasted requests.

Practical use cases

  • Conditional asset loading — only load Stripe.js on checkout pages
  • Dynamic meta tags — only render the meta block when content exists
  • Reusable layouts — components that gracefully handle empty slots

Real-world example: E-commerce checkout

Use @hasStack to load Stripe's JS only on pages that push to the checkout-scripts stack — keeps every other page free of unnecessary third-party scripts.

2. Route List Middleware Filtering

The route:list command now accepts a --middleware flag, letting you filter routes by the middleware they use. This is genuinely useful for security audits and debugging large applications.

# Show only API routes php artisan route:list --middleware=api # Show only authenticated routes php artisan route:list --middleware=auth # Filter by throttle middleware php artisan route:list --middleware=ThrottleRequests # Combine with path filter php artisan route:list --middleware=api --path=api/v1

This is particularly useful for checking which routes are protected by authentication, auditing rate-limited endpoints, and generating API documentation from the CLI.

3. Type Safety & Performance Improvements

Enhanced type hints

  • ResourceCollection$collection property is now properly nullable
  • Http::pool() — better type safety for concurrent HTTP operations
  • Exception handling — improved error message summarisation

Testing improvements

  • Parallel test supportWithCachedConfig now works correctly with parallel testing
  • Test generator--force flag now carries through to make:test
  • SQLite fixes — resolved stale connection issues in RefreshDatabase

Framework integration

  • Symfony 7.4 compatibility — updated Request::getAcceptableContentTypes()
  • Factory improvements — better array cast handling
  • Application builder — enhanced exception handling

4. Upgrading to Laravel 12.39

The upgrade is straightforward — 12.39 is fully backward compatible. Just update your dependencies and run your test suite:

# Update Laravel framework composer update laravel/framework # Or update all dependencies at once composer update # Verify everything works php artisan test php artisan route:list

Check the official changelog for the full diff, though no breaking changes are expected for standard applications.

5. What's Coming in Laravel 12.40

The community is already discussing what's next. The most anticipated additions include time interval helpers for more expressive date manipulation, enhanced queue pausing/resuming, instant column additions to migrations, and PostgreSQL full-text search support. Nothing is confirmed until it ships, but these are the PRs getting the most attention.

Conclusion

Laravel 12.39 is a focused quality-of-life release. The @hasStack directive solves a real template cleanliness problem, middleware filtering in route:list improves debugging workflows, and the type safety fixes reduce runtime surprises. Worth upgrading — and painless to do so.

For more on optimising your Laravel app, see the Laravel Performance Optimization guide and REST API Best Practices.

Need Help With a Laravel Upgrade or New Project?

I stay current with every Laravel release and apply the latest features in production. Happy to help with upgrades, performance, or building something from scratch.

Based in Bangladesh · Remote worldwide · Fast turnaround

About the Author

Kamruzzaman Polash — Software Engineer specialising in Laravel, REST APIs, and scalable backend systems. 10+ projects delivered for clients worldwide.