Fluent Base64 String Handling Encoding and decoding Base64 data often required jumping out of Laravel's fluent string chain to use native PHP functions. The 10.44 release streamlines this with `toBase64()` and `fromBase64()` methods. This change allows you to transform a string and encode it in one continuous, readable line. It removes the clunky nested function calls that typically clutter logic when handling binary data or API integrations. Array Take: Bringing Collection Power to Arrays Historically, the `take()` method was a beloved feature of Laravel Collections, allowing developers to grab the first or last few items using positive or negative integers. Now, the `Arr::take()` helper brings this exact functionality to plain arrays. You no longer need to wrap an array in a collection just to slice a few elements from the end. It's a small but significant win for performance and syntax consistency when working with raw data structures. The Rise of PHP Attributes in Eloquent The most impactful shift in this update is the introduction of PHP Attributes for Eloquent models. Previously, connecting a Model Observer required registering it in the `EventServiceProvider`, which separated the model from its logic. With the new `ObservedBy` attribute, you declare the observer directly on the model class. This keeps the relationship explicit and eliminates the need to hunt through service providers to find where events are being handled. Simplifying Scopes and Collections Similarly, Global Scopes can now be applied via the `ScopedBy` attribute, replacing the boilerplate usually found in a model’s `boot()` method. This declarative approach makes the model's behavior clear at a glance. On the collection side, the new `select()` method replaces the common pattern of using `map()` to isolate specific keys. Instead of writing a closure to return an array with certain fields, you simply pass the keys you want. It’s cleaner, more expressive, and feels like writing SQL directly on your objects.
Model Observer
Software Features
Feb 2024 • 1 videos
High activity month for Model Observer. Laravel among the most active voices, with 1 videos across 1 sources.
Feb 2024
- Feb 15, 2024