Upgrade Laravel constantly and safely

Mar 9, 2019 Laravel

Upgrading framework tends to be put aside because we often prioritize adding new features to products. However, if you don’t upgrade the framework for a long time, upgrading the framework will become a nightmare. Jumping from an old version to the latest version is not only a very tough job but also it’s dangerous due to a large number of changes. In this post, I’ll show you how to upgrade Laravel easily and safely using Laravel Shift.

A big jump is a nightmare

Last year, we upgraded the Lumen 5.1 application to Laravel 5.6 which was a lot of work. First of all, we had to upgrade PHP 5.6 to PHP 7.2 because Laravel didn’t support it any more. After upgrading PHP, we noticed that PHPUnit 4 didn’t support PHP 7 and so we tried to upgrade it, too. However, Lumen 5.1 only supported PHPUnit 4 😨 So, we ended up to upgrade Laravel and PHPUnit at the same time.

After a very tough work, we created a huge pull request with too many changed files. It was almost impossible to review all the changes.

Too many changed files

From this experience, I promised myself to upgrade the framework as soon as possible when a newer version is released.

However, one good thing was that we had written a lot of unit and integration tests. Even if something breaks, we could notice before releasing to production.

Laravel Shift is your friend

Laravel Shift

After upgrading to Laravel 5.6, the version 5.7 came out. This time we upgraded using Laravel Shift which saved a lot of time.

Laravel Shift is a service that scans your Laravel application and automatically creates a pull request for upgrading Laravel. All you have to do is just choose a repository and pay some money. In my case, it costed only $9 but the pricing depends on Laravel version of your application. After one or two minutes, you’ll receive a pull request with very detailed comments like this.

Excerpt of a pull request by Laravel Shift

You need to review changed files, check comments from Shift, run composer update and confirm that all tests pass. Especially, you should carefully check config files that are different from Laravel’s default values.

In my case, it took only a couple of hours to upgrade my Laravel application. It was super easy! I upgraded three applications using Shift. Thank you JMac for creating such a great service!

Write tests

Laravel Shift is a super useful service but it’s not perfect. It might break some existing functionalities. However, you can notice this before releasing to production and be more confident if you have test code. So, it’s very important to write tests every time you implement a new feature.

Error monitoring

Even if you write tests, it’s almost impossible to cover all cases. So, it’s also important to monitor application errors. In my case, I use Sentry for error monitoring. It’s very straightforward to install Sentry to a Laravel application.

When an exception is thrown in the application, Sentry will send you a notification. You can fix the error or roll back the release.


Recently Laravel 5.8 has been released! I’m planning to upgrade after one or two month later because there will be some patch releases for bug fixes.

avatar

About Me

I am a software engineer from Japan and currently based in Singapore. Over the past 5 years, I've been creating e-commerce and FinTech web applications using Laravel, Angular, and Vue.js. Making clean, maintainable, and scalable software with agile methodology is one of my biggest passions. Im my spare time, I play the bass and enjoy DIY.