Laravel 9.20, weekly updates, and πŸ”₯ tip

Laravel 9.20

Day delay on the release, but we get a couple new features this week in Laravel 9.20.

  • Allow passing callable to Collection random() in #43028
  • Add Str::inlineMarkdown() in #43126
  • Add replicateQuietly() to Model in #43141
  • Allow authorization responses to specify HTTP status codes in #43097
  • Add ignore property to ValidateSignature middleware in #43160

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 task for normalizing request access within a Laravel application. I actually started this in my live stream last Wednesday and finished it with the rest of the week. It's now available in the Shift Workbench.

I also had a few pairing sessions from Human Shifts. One was to help establish queues and the other was to implement policies.

I did another live stream today. This time to write some automation to expand compact() to an array when passing view data. There are a couple of common ways within the community. But it seems like using arrays is the most common. So I'll start there.

I'm nearing the end of my Todo List for Shift. With the new annual release cycles, I no longer have to worry about preparing a new Shift in August. So I'll likely continue creating new automation for the Workbench. If you have any ideas, let me know in a reply or on Twitter.

πŸ”₯ Tip

Similar to my tip from last week, sometimes I need to track state. I typically like to do this with a boolean flag.

When working on the automation last week I to needed to determine if I should remove some code, add some code, or do nothing. Strictly speaking, a boolean flag can hold three potential values: true, false, and null.

So I used such a flag to track these three states. However I was using a bitwise operator to manipulate the state.

$remove_facade |= true;

When I later strictly compared this to true, the removal code never executed.

After a couple of var_dump() statements, I realized even though I was typing it as a bool, it returned an int. As such the strict comparison failed.

Reading the documentation more closely, the bitwise operators return an integer.

While this makes sense, I assumed when passed a boolean value they would remain a boolean value. Since this flag could potentially be nullable, I couldn't simply cast it back to a bool.

So, a couple tips here…

First, you may track three states with a nullable, boolean flag. Just be mindful how you assign values to that flag.

Second, bitwise operators return an integer. To preserve a boolean value, I needed to use the boolean operators. In this case, writing:

$remove_facade = $remove_facade || true;

Unfortunately, there's no ||= shorthand.