Laravel 9.1, weekly updates, and 🔥 tip

Laravel 9.1

Lots of fixes in this week's release of Laravel 9.1 given the major release last Tuesday. However, I'm going to focus on the new features added.

  • Add @disabled Blade directive in #40900
  • Allows TLS encryption to use a different port in #40943
  • Catch suppressed deprecation logs in #40942
  • Add support for passing array for Route::group in #40945
  • Put the error message at the bottom of the exceptions in #40886
  • Add firstOr() to BelongsToMany relation in #40828
  • Ability to use uniqueFor in jobs in #40974
  • Add filtering of route:list by domain in #40970
  • Add dropForeignIdFor migration method in #40950
  • Add Str::excerpt in #41000
  • Add make:model --morph to generate MorphPivot model in #41011

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 was incredibly busy. Not only was the release of Laravel 9 on Tuesday, but Laracon Online was Wednesday. In the absence of the in-person conference, I like going to a viewing party. There's one Jacob Bennett hosts in Illinois. It's about a 4 hour drive. But it's good to hang with other devs like Matt Stypa, Kevin McKee, Jordon Brill.

Since the Shift feedback emails are on a two weekday delay, I didn't start receiving them until Thursday and Friday. So I spent both of those days patching some of the edge cases which were reported and improving automation.

As always, the largest issue was package compatibility. I continued using Shift to automated more compatibility PRs. I also noticed more of the original PR's getting merged. I think at this point most of the popular packages support Laravel 9.

To that point, I normally wait a week myself. Unless it's a really small project. I did upgrade BaseCode as I know I don't use many packages within that project. Using Shift, the Laravel 9 upgrade took 14 minutes and 59 seconds.

I plan to do another live stream this week to upgrade another one of my projects. I'll also start on all of the Human Shifts coming in for projects which follow LTS. Silly enterprise, LTS is a trap. 😉

🔥 Tip

In tracking down one of the bugs in Shift, I needed a way to determine the line in a file given a character offset.

Now there's all sorts of fancy one-liner commands out on StackOverflow. But thinking about the problem naively the algorithm is roughly:

// Get substring from 0 to offset
// Count line breaks within substring
// Add one

After using PHP for over 20 years, I know it's a scripting language at heart. As such, anytime I come across one of these problems I scroll through PHP's native array and string functions.

More often than not, I find the exact function I need. In this case substr_count. The end result is a one-liner even the StackOverflow answers didn't have 🔥

public function lineForCharacter(int $offset)
{
return substr_count($this->content, PHP_EOL, 0, $offset) + 1;
}