Upgrade to Laravel 6 from Laravel 5.8

Laravel 6 is finally released. It's the new LTS version of Laravel instead of Laravel 5.5.

How to update your project to Laravel 6?

The update process of a project to the latest Laravel 6 is easy.

Open the composer.json file of your project (The configuration file of Composer) and change the Laravel framework version from 5.8.* to ^6.0 (Notice the caret, Laravel 6 makes use of semantic versioning scheme).

If you have a version smaller than 5.8, you are recommended to first upgrade your project to 5.8 then again upgrade to v6.

Next, save your composer.json file and run the following command:

$ composer update

As said, the process is easy but in bigger projects, simply changing the package version in the composer.json file won't work because most likely your project makes use of some feature that has changed in Laravel 6.

If you have created your project with Laravel 5.8 or you have an existing project that was already upgraded to v5.8, these are the changes that you need to perform before upgrading to the latest Laravel 6 version:

Updating PHP to PHP 7.2+ required by Laravel 6

Before you upgrade your project to v6, make sure your upgrade your PHP version from 7.1 to at least 7.2.

starting from December 2019, PHP 7.1 will not be maintained.

Updating the laravel/framework package to ^6.0

After you update your PHP version to v7.2+, you then need to update the framework dependencies, you can do that by simply opening the composer.json file of your project where Composer stores the information about the locally-installed packages of the project and changes the laravel/framework package to ^6.0.

What does the caret means? It simply means, that it's ok for Composer to install a newer minor or patch level version instead of the same exact version. This is part of semantic versioning that Laravel 6 started to use.

You also need to check the other packages and update them to versions compatible with Laravel 6.

Add a viewAny() method to authorization policies for controllers

If you have added any authorization policies using the authorizeResource method in one of your controllers, you should now add a a viewAny() method or access to the index() method will be unauthorized.

Add an $allowed argument to the constructor of your authorization responses

If you have defined any authorization responses using the Illuminate\Auth\Access\Response class, you should change the signature of the __construct() method or constructor by adding an $allowed argument as follows:

public function __construct($allowed, $message = '', $code = null)

Add an inspect method to any implementations of the Gate interafce

You also need to add an inspect method to any implementations of the Illuminate\Contracts\Auth\Access\Gate interface in your code.

Upgrade your project to use Carbon 2.0

Carbon 1.x is no longer supported so you need to upgrade your project to use Carbon 2.

Set the redis.client configuration option to predis in your config/database.php file

In Laravel 6, the default Redis client is phpredis so you need to set the redis.client configuration option to predis (the old default used in your project) in your config/database.php file.

Using Laravel Shift

You can also ugrade your project using Laravel Shift, an online automated service that helps you manage your upgrades. It will automatically do the upgrade process and the required changesfor you.

Do you have to upgrade?

In most cases, yes because Laravel 6.0 is the latest Long Term Support release insted of Laravel 5.5, so that means bug fixes will be provided for two years and security fixes for three years.

Conclusion

We have seen a list of changes that you need to perform in order to upgrade your Laravel 5.8 to Laravel 6. There are many other changes that you may need to make depending on your project. Check out the complete list from the official docs

Note: We also publish our tutorials on Medium and DEV.to. If you prefer reading in these platforms, you can follow us there to get our newest articles.

You can reach the author via Twitter:

About the author

Ahmed Bouchefra
is a web developer with 5+ years of experience and technical author with an engineering degree on software development. You can hire him with a click on the link above or contact him via his LinkedIn account. He authored technical content for the industry-leading websites such as SitePoint, Smashing, DigitalOcean, RealPython, freeCodeCamp, JScrambler, Pusher, and Auth0. He also co-authored various books about modern web development that you can find from Amazon or Leanpub


Get our Learn Angular 8 in 15 Easy Steps ebook in pdf, epub and mobi formats, plus a new Angular 8 tutorial every 3 days.


Online Courses (Affiliate)

If you prefer learning with videos. Check out one of the best Angular courses online
Angular 8 - The Complete Guide (2019+ Edition)

Angular Crash Course for Busy Developers

comments powered by Disqus
DMCA.com Protection Status