Laravel 11.1 Essentials: Smarter Enums, Auto-Hashing, and Global Context

Laravel////2 min read

Refined Enum Queries in Eloquent

has long supported PHP enums for casting, but a significant friction point remained when querying databases. Previously, while you could cast a model attribute to an enum, passing that same enum directly into a where clause often led to unexpected failures. The framework now handles this natively. You can pass a backed enum case directly into query methods, and it correctly resolves the underlying value. This eliminates the need for manual ->value calls, making your repository and service layers significantly cleaner.

Automatic Password Re-hashing

Security standards change, and now makes it easier to keep up without forcing a mass password reset. The framework has updated its default work factor from 10 rounds to 12, matching standards. The real magic happens during authentication: if a user logs in and the framework detects their stored hash uses an outdated work factor, it automatically re-hashes the password using the new configuration. This ensures your user data stays secure against modern brute-force hardware without any manual migration scripts.

Capturing Metadata with Context

Modern applications involve complex request lifecycles—controllers, jobs, and listeners often need access to the same metadata. The new facade provides a centralized way to store information that persists across the entire request. By adding a simple middleware, you can inject data like request IDs, current URLs, or authenticated user IDs into the global context. This data is automatically appended to log messages, providing an incredible audit trail for debugging without cluttering your code with repetitive log context arrays.

Beyond Logging: Hidden Context

The Context feature isn't just for logs. Developers can store hidden data that doesn't appear in logs but remains accessible throughout the execution thread. This is perfect for passing tenant IDs in multi-tenant apps or tracking internal execution flags. By centralizing this metadata, you reduce the need for passing variables through deep call stacks, keeping your method signatures focused on their primary logic.

Topic DensityMention share of the most discussed topics · 8 mentions across 8 distinct topics
13%· products
13%· products
13%· products
13%· products
13%· products
Other topics
38%
End of Article
Source video
Laravel 11.1 Essentials: Smarter Enums, Auto-Hashing, and Global Context

Re-hashed Passwords, Improved Enum Support & Context

Watch

Laravel // 7:26

The official YouTube channel of Laravel, the clean stack for Artisans and agents. We will update you on what's new in the world of Laravel, from the framework to our products Cloud, Forge, and Nightwatch.

Who and what they mention most
2 min read0%
2 min read