Laravel 9.47, weekly updates, and π₯ tip
Laravel 9.47
Mostly fixes this week with a few new features brings us to Laravel 9.47. Here are the highlights:
- Support lazy collections in
BatchFake
in #45507 - Fix bound method contextual binding in #45500
- Return model when casting attribute in #45539
- Support destroyable singletons in #45549
- Add
setVisible
andsetHidden
to Eloquent collection in #45558
You may review the full branch diff on GitHub for a complete list of changes.
This version bump and update is automated for subscribers to a Shifty Plan. If you don't have one of those, be sure to bump your constraint and run composer update
to get the latest features.
Weekly Journal
A fresh batch of Human Shifts came in last week. This is expected with the new year and the upcoming release of Laravel 10. The release often serves as a reminder to finally get their applications upgraded.
I worked on those last week and will continue on them this week. I hope to live stream tomorrow to submit some last minute changes for Laravel 10. In the coming weeks I'll stream about building the Laravel 10.x Shift.
Unfortunately though Izzy is sick again. So who knows if I'll have time to work on these items. We're still working out the logistics of two children. Especially when one of them is sick.
π₯ Tip
I gripped about this on Twitter, but a pattern I notice these upgrades is injecting empty models into classes. Particularly other models.
It's important to note these not a specific record as you might pass to a job or service class. These are simply instances of a model class used to call methods within the model or build Eloquent queries.
There is, of course, no reason to do this. Eloquent allows you to call models statically. Eliminating this practice not only reduces the constructor code, but reduces the code in the application by not having to rely upon the container. It would also reduce code in tests because they likely mock the injected models.
On that note there's rarely a need to ever inject anything into core Laravel classes. Instead, you may resolve directly from the container or use modern features like real time façades.
In addition, Laravel's robust testing layer allows you to easily swap classes through the container or test a component of your application in a more integration style.