This is How I Upgrade My Laravel 8 Project to Laravel 9

Check this article on Medium: @ngodingbang/this-is-how-i-upgrade-my-laravel-8-project-to-laravel-9-962e96964133

You may want to read this article in Bahasa Indonesia version: Cara Upgrade Projekmu dari Laravel 8 ke Laravel 9

TL;DR

In the previous article, I’ve been sharing some of the features and update on the latest version of Laravel framework which is Laravel 9. Now I’m gonna let you know how I upgrade my Laravel project from Laravel 8 into Laravel 9. My project called BCA Denpasar Chatbot is a queuing system used by Bank Central Asia at Denpasar Branch office in Bali that has been re-invented using the bot feature of Telegram. This is an open source project that I’ve been put it on GitHub, so you can check it out later after read this article.

ianriizky/bcadenpasar-chatbot

ianriizky/bcadenpasar-chatbot

Message automation system using chatbot to handle online exchange of small and new money using PHP and Laravel Framework (Case Study: PT. Bank Central Asia Tbk. Denpasar Branch).

Read more...

Now let’s dive into it step-by-step!

This is how Laravel force you to using – at least – the latest version of PHP, since we all know that PHP 7 has come to an end by 2 months ago since this article was published.

PHP Supported Versions (by 13 February 2022)
PHP Supported Versions (by 13 February 2022)

So before I upgrade my Laravel, I have to make sure that my PHP version on the server has been upgraded into PHP 8. Also don’t forget to update the required PHP version of the project in the composer.json.

PHP version on composer.json
PHP version on composer.json

Then I change some of the require package here below in composer.json:

  • laravel/framework to ^9.0
  • nunomaduro/collision to ^6.0

As the addition, I also change the using of package facade/ignition to “spatie/laravel-ignition”: “^1.0” in composer.json as Laravel mention this on their official documentation. I’ll leave that link later at the source part, so check that if want to know more about that.

Some of the require package needs to change on Laravel 9
Some of the require package needs to change on Laravel 9

The next step is running this command in my terminal: composer update.

Note: If you curious to know what packages will changed after running composer update command without without changing the contents of composer.json and composer.lock, you are suggested to use flag --dry-run after composer update.

If we take a look at Laravel’s official documentation in the Trusted Proxies section, we will see that there is a section that needs to be changed in app/Http/Middleware/TrustProxies.php. So the class inheritance that was previously directed to the Fideloper\Proxy\TrustProxies class is now changed to Laravel’s class Illuminate\Http\Middleware\TrustProxies. For more details you can see in the image below.

Changing of TrustProxies on Laravel 9 (Source: https://laravel.com/docs/9.x/upgrade#the-assert-deleted-method)
Changing of TrustProxies on Laravel 9 (Source: https://laravel.com/docs/9.x/upgrade#the-assert-deleted-method)

And finally, at last but not least …

Luckily I already create the unit and feature test of this project, so I can run the command php artisan test to make sure that my project is still running well after upgrade process finished.

Conclusion

For more information, you can visit the official Laravel guide for upgrading from Laravel 8 to Laravel 9 at https://laravel.com/docs/9.x/upgrade#upgrade-9.0. If you have some problem during the upgrade process, don’t hesitate to share your problem here at the comment section. There are so many things you can explore on Laravel 9, so it never hurts to try upgrade your Laravel project also to Laravel 9.


Source

Related Content