< go back to home

My Guide For Laravel 7 to 8 Upgrade

October 24, 2020

I recently upgraded a production side-project iVolunteer from Laravel 7 to 8. It was an interesting experience which I will share as this can also serve as step-by-step guide that can help.

To start with, it is absolutely required that you have an automated-testing in place. At least within the level of unit and integration testing. Otherwise, you won't have confidence that no critical failure occured.

Upgrading Laravel version actually means two parts. First is updating the library itself in the Composer. This includes other Composer library dependencies. This one is pretty straightforward where you just have to follw the steps in the Laravel upgrade documentations.

The next part is updating the codebase itself that is outside of Composer. This is accesible in the Github repository. You will have to check the Github comparison tool to see which files and what lines were changed. You will make decision to incorporate and merge those changes to your codebase. This is where you earn your money as a software developer. I'll now proceed to explain in more details what I did.

The first is to scan through the Laravel 8 from 7 guide here. You may start updating your codebase as instructed from top to bottom. The most important is updating your dependencies in Composer and running "composer update". I did not experience any issues in the updating of libraries.

After updating Composer seamlessly, all the testing broke. This is because of the new feature "model factories". It is important to immedeatel get tests going again as I heavily rely on those to determine if something was broken. To fix that, you will just have to install a library.

I also had to deal with the new frontend features which broke the paginator styling. It was quickly addressed by adding the line "Paginator::useBootstrap();" in "app/Providers/AppServiceProvider.php". After that, those are it for the first part in me. Yours might be more, but the changes are documented and it's easy to follow.

The next part is updating the codebase itself, each file. This is easier than it sounds because of Github comparison tool . Go to the "Files changed" tab. There you'll see the changes in each file and you'll decide on whether and how to manually merge those changes.

An example is in "app/Exceptions/Handler.php" where error handling has been updated. "report()" function is replaced by "register()". You'll have to be careful here if you have overriden error handling and follow on Laravel 8's implementation. Lucky for me, there was no changes there on the project.

Basically that's it for the upgrade of Laravel 7 to 8. It's pretty hard to put a step-by-step guide as a large part of it is case-by-case basis. It comes down to 1. follow official upgrade guide and 2. update your codebase based in Github comparison tool . The key here is to have an automated testing in place. Happy coding!