Update your project to Laravel 6 from Laravel 5.8

Update your project to Laravel 6 from Laravel 5.8

tudip-logo

Tudip

03 April 2020

To start the process of updating the project to the latest Laravel 6, open the composer.json file of your project and change the Laravel framework version from 5.8.* to ^6.0.

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

Now, save your composer.json file and execute the following command:

composer update

The process is easy but in bigger projects, just changing the package version in the composer file won’t work as most likely your project is using some feature that has changed in Laravel 6.

If your laravel version is 5.8 or you have an existing project that was already upgraded to v5.8. So you need to perform following changes before upgrading to the latest Laravel 6 version:

Requirements

Before upgrading your project to v6, you must have to upgrade your PHP version from 7.1 to at least 7.2. Starting from December 2019, PHP 7.1 will not be maintained.

Updating Dependencies

Open Composer.json file and change the laravel version from 5.8.* to ^6.0. If your current Laravel version is less than 5.8 then you are recommended to upgrade to 5.8 first and then again upgrade to v6.

If you are using any third party packages, please verify that your package is supported by the Laraavel version v6.

Upgrade carbon:

Carbon 1.x is no longer supported in the upcoming versions. Please upgrade your application to Carbon 2.0

Redis client:

Default Redis client changed in Laravel. Default Redis client in laravel 6.0 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.

The cursor Method:

The return type of the cursor method is updated in  v6. Now it return an instance of Illuminate\Support\LazyCollection instead of a Generator The LazyCollection may be iterated just like a generator.

$users = App\User::cursor();
foreach ($users as $user) {

//

}

Queues:

In older versions of Laravel, the php artisan queue:work command would retry jobs indefinitely. Beginning with Laravel 6v, by default this command will try job just one time. You can force jobs to be tried indefinitely by passing 0 to the –tries option:

php artisan queue:work --tries=0

You should have failed_jobs table in your application’s database. You can generate a migration for this table by using the following command:

php artisan queue:failed-table

Declaration Of Primary Key Type:

Laravel v6 has received performance optimizations for integer key types. You need to declare the key type using the $keyType property on your modal, if you are using a string as your model’s primary key

/**

 * The "type" of the primary key ID.

 *

 * @var string

 */

protected $keyType = 'string';

Conclusion

We have gone through a list of changes that need to be performed in order to upgrade your Laravel 5.8 to Laravel 6. There are many changes that you need to make in your project, it depends upon your project. You can check the complete list on the official docs

search
Blog Categories
Request a quote