Laravel 12.17, weekly updates, and weekly tip

Laravel 12.17

Couple features this week brings us to Laravel 12.17.0. Here are the highlights.

  • Ability to perform higher order static calls on collection items in #55880
  • Add resource helpers to the cursor paginator in #55879
  • Add reorderDesc() to query builder in #55885
  • Add AsUri model cast in #55909
  • Add contextual binding via PHP attribute in #55904

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

I returned from vacation over the weekend. Today Emma started daycare. So I'm hoping to actually get back into the code this week.

A Human Shift came in at the end of last week. I started with that, to upgrade from Laravel 7.x to Laravel 12. In combination with support emails, I then made a few tweaks to Shift.

I also completed the conversion to local currency. Stripe has all of these hidden restrictions with products. Specifically around adjusting prices. For example, you can't change the price of a product once it has been purchased. You basically have to make a brand new product. Which of course means code changes.

The same goes for subscriptions. I can't change the currency of an existing subscription. So to grandfather subscribers into their local pricing, I made a script which resubscribes right they renew. I launched that Monday. Although there are no more code changes, it won't be until the end of the year until everyone is converted Stripe Checkout and local currency.

With the rest of this week, I'll start a new livestream series building a website for a local house cleaning service. I'm going to use AI to generate the design and Laravel and Tailwind to fill in the rest. It'll probably be a four part series. Feel free to join me on Twitter or YouTube.

There are just over 10 copies left of the BaseCode print edition. I don't think I'll print any more. So if you want to be one of the 50 people that have a copy, now is the time.

Weekly Tip

Date math is always a bit brain bending. I recently added a notification to laravelshift.com to display your upcoming subscription renewal. I attempted to use what I thought were the right, expressive Carbon methods.

@if($renew_at->isAfter(now()->subDays(20)))

But this continued to display the notification after their subscription renewal. Instead of just 20 days before.

Complex logic is pretty subjective. You have to find the logic that makes sense in your head. This is unfortunate because I aim to write readable code. That is code which is universally readable. Not just by me.

Comparing if a date is before or after is pretty simple. But what about comparing a relative date or a date within a range. Clearly not so simple (at least for me).

Now, I'm sure I could have adjusted the comparison above to isBefore, or changed the arguments, or added instead of subtracted days (or some combination - you're welcome to tell me).

In the end, I stumbled upon isBetween. Which I feel is much more readable to a much larger number of devs.

@if(now()->isBetween($renew_at->subDays(20), $renew_at))

If now is between 20 days before the renewal and the renewal, then show the notification.