Zinq zinq

Upgrading to Laravel 12 - what you need to know

Posted on: February 25, 2025 by Matt

Today we're diving into a topic that will eventually affect all of us - upgrading our framework to the latest version. Laravel 12 is now available, so it's time to look at the migration process from version 11.

# Good News - no revolution!

First, let me reassure you - moving from Laravel 11 to Laravel 12 isn't a revolutionary change. The Laravel team continues their philosophy of evolving the framework gradually, making the upgrade process relatively simple and painless.

# Two Upgrade Paths

As always, we have two options to choose from:

  1. Laravel Shift - If you prefer a more automated approach, Laravel Shift remains an excellent tool that will do most of the work for you,
  2. Manual Upgrade - Personally, I recommend this option as it helps you better understand the changes and gives you complete control over the process. Additionally, it's a good opportunity to refactor certain parts of your code.

# Free Compatibility Checker

Before you start, LLaravel Shift offers a free tool where you can check if your project is ready for Laravel 12. Simply copy your composer.json and paste it into their tool to see if all your packages already support Laravel 12: Can I Upgrade Laravel?

This can save you a lot of time by identifying potential compatibility issues before you begin the upgrade process.

# Key Changes in Laravel 12

Before starting the upgrade process, it's worth familiarizing yourself with the official documentation: Laravel 12.x Upgrade Guide.

# Most Significant Change: Carbon 3.x

The most notable change in Laravel 12 is the removal of backward compatibility for Carbon 2.x. If you use Carbon 2.x functions in your projects, you'll need to refactor your code to Carbon 3.x.

For example, if you have something like this in your code:

 
// Carbon 2.x - won't work in Laravel 12
$date = Carbon::now();
$formattedDate = $date->formatLocalized('%A %d %B %Y');

You'll need to update it to:

 
// Carbon 3.x - compatible with Laravel 12
$date = Carbon::now();
$formattedDate = $date->translatedFormat('l d F Y');

# Step by Step - The Upgrade Process

Here's how you can perform the upgrade manually:

  1. Update dependencies in composer.json :
 
{
    "require": {
        "php": "^8.3",
        "laravel/framework": "^12.0"
    }
}
  1. Update packages:
 
composer update
  1. Migrate Carbon code:
  • Identify all places where you use Carbon 2.x
  • Change them according to Carbon 3.x documentation
  1. Test your application
  • Run unit tests
  • Check the functionality of key features
  • Pay special attention to date manipulation

# Summary

Upgrading to Laravel 12 shouldn't be a painful process. The lack of revolutionary changes means we can enjoy new features without having to completely rebuild our applications.

As always, I recommend a gradual approach:

  1. First, update smaller projects
  2. Gain experience with the new features
  3. Then move on to updating larger, more critical applications

Good luck with your upgrade!


Newsletter

Join other developers and never miss out on new tips, tutorials and Zinq updates!