DEV Community

JcRodSolutions
JcRodSolutions

Posted on

Upgrade to Laravel 10 from v9

This may be a late post, but I'm still writing this as my wording may help some of you to understand it in a way others tried and failed.

First of all, you are required to upgrade your PHP version to at least 8.0.x, in my case I have PHP 8.2 for this example. Remember PHP 8.3 is coming soon...

My current example

Here I have just a few packages but what matters is how I make sure, or at least make a good guess, that every one of them will be compatible.

My composer.json

BEFORE YOU BEGIN

Backup your code!!
If you have git for version control, create a separate branch. This way you have the option to start again in case you screw up. Also it will make a kind of checkpoint in case you want to practice over and over.

git branch L10 will create a new branch called L10
git checkout L10 will change your current branch to the new one

Step 1

After checking your current Laravel Framework with php artisan --version or php artisan about, open your composer.json with your favorite IDE/Editor.

Step 2

This is a long one, but with each project you upgrade you will get better and faster at this.

Check every package to see if the version rule defined in your composer version will work. Let me explain using the following image:

Packagist Semver Checker
I present to you Packagist Semver Checker. With this marvelous tool you can check the versions covered by your rule. In this example we can see that doctrine/dbal will upgrade fine when we run the final step which is composer update.

Step 3

Rinse and repeat.
At the end of this cycle I get the following in the required section. The most important version upgrades are PHP and laravel/framework.

Image description

Step 4

In the console, excecute the command
composer update
.. and you are ready to go!

uh-oh!

Not so fast my friend. You may encounter different issues telling you that it's not ready to upgrade ... yet

Image description

But don't worry, it isn't usually that hard. You just have to read carefully and you'll get your issues fixed.

In my case, I have 2 main issues and this is how to fix them.

composer update errors

The first one I would like to mention is the package spatie/laravel-ignition which I haven't set to ^2.0.
Remember Semver Checker? Well, it will help you determine that your rule should say ^2.0 for spatie/laravel-ignition by telling you that there are higher major versions than 1.x so my composer.json looks like this in the "require-dev" section:

composer.json require-dev

I Promise, we are almost there

For my project, this was all it take to complete upgrade requirements. But there are sometimes that Illuminate/support keeps telling you that it's not supported for the actual dependencies.
To fix this issue, first thing I try is a little bit harsh but quite effective:
rm -rf vendor composer.lock which eliminates both, vendor folder and composer.lock file. Then you can try composer update again and it will most likely succeed.

For you who don't know what is composer.lock for, I'll try to make it simple (it has a lot more detail): This file has the actual versions of all the packages defined in composer.json file plus all dependencies. When you delete composer.lock and then you try composer install or composer update it recalculates all dependencies and create a new composer.lock file while installing all vendor files.

Finally, we are done!

Check again your version

artisan --version
** pa is my shortcut for 'php artisan'

Now that your project is successfully upgraded to Laravel 10, serve it and have a look so you can make sure everything works before committing and merging your changes to your dev, qa and/or main branches.
You should only have these two files waiting for a commit.

git status

As I said, after your revision you are now ready to commit your changes.

git add .
git commit -m "Project upgraded to Laravel 10"
git checkout dev
git merge L10
git push
Enter fullscreen mode Exit fullscreen mode

Rollback

If anything goes wrong, just change branch to your last working branch, remove your vendor folder and run composer install to reinstall your original files as defined in composer.lock file.

git checkout dev You may need to --force
git branch -d L10 to delete the failed attempt

and... you are ready to try again without messing up with your currently working code.

See you later

I hope this tutorial help you to understand what the process of upgrading Laravel to v10 from v9.

Soon I'll be posting an article on how to upgrade from 8 to 9.

Feel free to comment with your questions.

Top comments (0)