Laravel 12 Release

Laravel 12.0.0

Early Monday Laravel 12.0.0 was tagged. Laravel 12 is being called a maintenance release with "no breaking changes" (for most apps).

While the Laravel 12.x Shift has been out for a few weeks, it's not final until the official release is tagged. It's actually never final. I'm always making small tweaks.

Before moving on, I will say now is the best time to subscribe to a Shifty Plan. That's because until the end of March the Latest plan still includes the Laravel 10.x Shift. So if you're still running Laravel 9, it's a no-brainer. Of course, if you're running an older version of Laravel, the Legacy plan is also a no-brainer.

Alright, I'm done pitching. Let me talk about Laravel 12 and the Laravel 12.x Shift.

Around the release, I get more active on Twitter and Reddit. Better or worse, they're still my best channels for reaching new users. The common response I get when sharing the Laravel 12.x Shift is, "why use Shift, there are no breaking changes?" And, "it only took my 10 seconds to upgrade myself."

I like to think I'm good at remaining objective. I've been called Spock by multiple people over the years. A compliment professionally. Maybe not personally.

Anyway, I can objectively say that if you have an app you started on Laravel 11, especially a recent version of Laravel 11, then you probably don't need to run the Laravel 12.x Shift. Just follow the Upgrade Guide. It'll take you longer than 10 seconds. But you're unlikely to be affected by any changes.

If you're app was older than Laravel 11 or has a lot of dependencies, then I truly believe the Laravel 12.x Shift is still faster and more thorough than doing it yourself.

Shift has always gone above and beyond the Upgrade Guide. In fairness, they have two different goals. Laravel's goal is to get you running the latest version - with minimal friction. Shift's goal is to make your app look and feel like it was always running that version of Laravel.

That means always upgrading core files, merging configuration options, and bumping your dependencies. But every Shift does all of the "optional" changes too. Plus, I like to automate at least one big change. For the Laravel 10.x Shift it was type hints. For the Laravel 11.x Shift it was the slimming.

For the Laravel 12.x Shift, without many breaking changes, it was the first time I got to focus on true refactors. So, in addition to what's in the Upgrade Guide and the basic automation noted above, here are some of the refactors the Laravel 12.x Shift performs.

Adopting PHP attributes in models

The last few versions of Laravel have adopted PHP attributes. There are several available, but two that I think are more common are #[ScopedBy] and #[ObservedBy]. First and foremost, I like these because they streamline code (more removed than added).

I also like these because they centralize the communication of side effects. You might argue scopes and observers aren't always easy to spot within an application. A PHP attribute right at the top of your model class, provides a common way to communicate this.

So, the Laravel 12.x Shift refactors your code to use these new attributes.

Removing old base controller traits

A fresh Laravel app no longer comes with traits in base controller. Laravel instead documents using the new application configuration, request validation, or facades directly.

An example of this are the $this->authorize methods within controllers. The Laravel 12.x Shift will convert these to use their equivalent Gate::authorize methods. This is the code demonstrated in the examples from the Laravel Documentation. Again, this refactor aligns with Shift's goal of making your app look and feel like Laravel 12.

Using the controller middleware method

Along the same lines, Laravel now registers a controller middleware within its own static method, instead of $this->middleware within a controller constructor. The Laravel 12.x Shift will convert any controller middleware to the new method.

Again, this is to modernize your code to and align it with the examples in the docs. I also like it for the same reasons as the PHP attributes - it more clearly communicates controller middleware.


So, those are some of the highlights of the Laravel 12.x Shift. If you'd like to see it in action, there's a demo video on the page and I've also done livestreams upgrading my apps. Of course, whether or not your use Shift, before you embark on an upgrade use Shift's Can I Upgrade Laravel tool to check compatibility.

As always, don't hesitate to reply with any feedback.

Start Shifting!