Laravel 9.21, weekly updates, and 🔥 tip
Laravel 9.21
Couple new features, but mostly a fresh new look for artisan
commands this week in Laravel 9.21. Also a long awaited convention is now official.
- A fresh new look for Artisan commands in #43065 and #43252
- Add
whenCounted()
to JsonResource in #43101 - New
model:show
Artisan command in #43156 - New
about
Artisan command in #43147 - Add
enum
type casting toRequest
in #43239 - Use
readpast
query hint instead ofholdlock
for SQLServer database queue in #43259 - Add
--existing
option to only publish existing files in #43212
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
Last week I finished up the new "View data array" task for the Shift Workbench. I wrote most of this during my weekly live stream.
I also took the opportunity, as with all tasks, to run it on my own code. It actually found 6 old instances where I was using compact()
.
I spent the last part of the week finishing the remaining Human Shift reworking some old auth code.
I was pretty sick over the weekend. I finally started feeling a little better today. So I took the opportunity to add support to Shift for using Laravel Pint to format code. Pint already surpassed the ruleset I shared Now that Pint is official, it's one less thing I need to maintain for Shift.
It's also a big win from a support perspective. Some of the more challenging emails I still receive relate to code formatting. Specifically with their not being an official Laravel code style. As such, Shift should not apply one. Today, that is no longer the case. Not only is there an official code style, but there is an official tool which you may use to apply it.
🔥 Tip
Something I continually stumble upon but haven't shared is the difference between all()
and toArray()
when using collections.
Until recently, I used toArray()
whenever I wanted to convert a collection to an array. Seemed like the right choice given the name. However, toArray()
not only returns an array, but recurses the entire collection and converts any underlying collection to an array.
This is not only less performance, but more importantly, may not be the behavior you want. For example, if you want to retain the type for underlying elements.
Now, I use all()
by default. This simply returns the top level elements within the collection as an array. It's quick, and aligns with the behavior I expect. If I know I'm dealing with nested data where I would potentially need to change the type, then I would reach for toArray()
.