Upgrade laravel to 5.7 [Step by Step Guide]

Upgrading laravel application from 5.6 to 5.7

In this article, we will discuss how to upgrade laravel 5.6 application to laravel 5.7. Laravel is one of the best PHP framework. Currently, laravel has a very large active communiny. Laravel has been continuously improving and adding new features since its first release. The latest version of laravel is 5.7. All of the new features explained in details can be found in this article. If you want to dig dig in more detail about creating application with laravel 5.7, you can read this article.

Upgrading to laravel 5.7 need some pre-requisities like PHP >= 7.1.3, OpenSSL PHP Extension, PDO PHP Extension, Mbstring PHP Extension, Tokenizer PHP Extension, XML PHP Extension, Ctype PHP Extension and JSON PHP Extension.

Below are the steps you need to follow to upgrade to laravel 5.7 from 5.6.

Update Dependencies

The first step to upgrade laravel/framework dependency in the composer.json file. In this composer.json file, upgrade laravel 5.6 to laravel 5.7. If you are using Laravel Passport, you should update your laravel/passport dependency to ^7.0 in your composer.json file.

Similarly, we need to replace the version of third party dependencies to * so that composer will install the compatible version of the packages used automatically.

After changing these dependencies, we need to run composer update command in the terminal. The composer will now update your our laravel application to the specified version along with all the packages.

Update Application

There are various application level update in laravel 5.7. After updating dependencies, we need to check the below traits and methods.

Blade or operator

We used to write or in our blade file to define default value in laravel 5.6. But in laravel 5.7, it has been removed. Rather, PHP’s built-in ?? “null coalesce” operator has been introduced with same functionality. You can read more information about this PHP features in this article.

Routing

The Route::redirect method now returns a 302 HTTP status code redirect. The 302 HTTP status code refers to moved temporarily. It tells the client to look at (browse to) another url. The permanentRedirect method has been added to allow 301 redirects.

Cache

A new directory for cache has been added in storage/framework/cache directory in laravel 5.7. We need to create this directory manually. After creating the directory, a need file .gitignore should be added.

The register Method

The options argument in register method of Illuminate\Foundation\Application class has been removed. If you are overriding this method, you should update your method’s signature:

The Authenticate Middleware

The authenticate method in laravel 5.6 used to only accept array $guards argument. But in laravel 5.7, it accepts $request as first argument. If there has been some change in this middleware, we need to update the signature.

The ResetsPasswords Trait

The sendResetResponse method in ResetsPasswords trait used to accept only $response as a parameter. But in laravel 5.7, it now accepts the incoming Illuminate\Http\Request as its first argument. If you are overriding this method, you should update your method’s signature:

The SendsPasswordResetEmails Trait

The sendResetLinkResponse method in SendsPasswordResetEmails trait used to accept only $response as a parameter. But in laravel 5.7, it also now accepts the incoming Illuminate\Http\Request as its first argument. If you are overriding this method, you should update your method’s signature:

The Gate Contract

The raw method was changed from protected to public visibility. Any class implementing this interface should add this method to your implementation.

The softDeletesTz Migration Method

The softDeletesTz method in Illuminate\Database\Schema\BluePrint class used to accept only $precision as a parameter. But in laravel 5.7, it also now accepts the column name as its first argument.

The ConnectionInterface Contract

The Illuminate\Contracts\Database\ConnectionInterface contract’s select and selectOne method signatures have been updated to accommodate the new $useReadPdo argument:

Email Verification

When using Laravel’s new email verification feature, you will need to add additional scaffolding to your application. First, add the VerificationController to your application: App\Http\Controllers\Auth\VerificationController.

You will also need to modify your App\User model to implement the MustVerifyEmail contract. More information can be found in about sending verification email after registration in laravel 5.7 in this article.

These are some of the key points to be noticed during upgrade from laravel 5.6 to laravel 5.7. You can find all the list in this documentation.