Upgrade Guide


Estimated upgrade time: 10-15 minutes

Note: This document demonstrates the upgrade from 5.6 to 5.7

Update Dependencies

stay composer.json Update in laravel/framework Depends on 5.7.*

Of course, don't forget to check whether the third-party expansion package used by the application supports Laravel 5.7, and update it if necessary.

App

register method

Removed Illuminate\Foundation\Application class register Unused parameter in method options , if you override this method, you need to update the method signature:

 /** * Register a service provider with the application. * * @param  \Illuminate\Support\ServiceProvider|string  $provider * @param  bool   $force * @return \Illuminate\Support\ServiceProvider */ public function register($provider, $force = false);

Artisan

Scheduling task connection&queue

If the connection/task is not explicitly passed to job Method, $schedule->job Method will now recognize the queue and connection Property.

This will be considered as a bug fix. However, for caution, it will be listed as an important update. If you have any doubt about this, you can go to here Submit a pull request.

authentication

Authenticate middleware

Illuminate\Auth\Middleware\Authenticate Middleware authenticate The method will be updated to $request As the first parameter, if you are in your own Authenticate This method is rewritten in the middleware, and the signature of the middleware method needs to be updated:

 /** * Determine if the user is logged in to any of the given guards. * * @param  \Illuminate\Http\Request  $request * @param  array  $guards * @return void * * @throws \Illuminate\Auth\AuthenticationException */ protected function authenticate($request, array $guards)

ResetsPasswords Trait

ResetsPasswords Protected in trait sendResetResponse Method now receives Illuminate\Http\Request As the first parameter, if you override this method, you need to update the method signature:

 /** * Get the response for a successful password reset. * * @param  \Illuminate\Http\Request  $request * @param  string  $response * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse */ protected function sendResetResponse(Request $request, $response)

SendsPasswordResetEmails Trait

SendsPasswordResetEmails The protected method of trait sendResetLinkResponse Receive now Illuminate\Http\Request As the first parameter, if you override this method, you need to update the method signature:

 /** * Get the response for a successful password reset link. * * @param  \Illuminate\Http\Request  $request * @param  string  $response * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse */ protected function sendResetLinkResponse(Request $request, $response)

to grant authorization

Gate contract

raw Method visibility from protected Adjust to public , the method declaration is also added to the Illuminate/Contracts/Auth/Access/Gate Covenants:

 /** * Get the raw result from the authorization callback. * * @param  string  $ability * @param   array|mixed  $arguments * @return mixed */ public function raw($ability, $arguments = []);

If you implement this interface, you need to add this method to the implementation.

Blade

or Operator

Blade's or The operator is removed because the PHP built-in ?? Operator to replace:

 // Laravel 5.6... {{ $foo or 'default' }} // Laravel 5.7... {{ $foo ?? 'default' }}

Carbon

Carbon's "macros" are now directly handled by the Carbon library, instead of the previous way of handling them through the Larravel expansion package. We hope that this will not affect your existing code, Welcome to give us feedback

aggregate

split method

split The method is updated to always group the collection according to the number of requests, unless the total number of entries in the original collection is less than the number of requests for grouping. Usually, this will also be regarded as a bug fix. However, to be cautious, we will list it as an important update.

Cookie

Factory Contract Method Signature

Illuminate/Contracts/Cookie/Factory Interfaced make and forever Method signature Has been modified If you implement this interface, you need to update these methods in the implementation class.

data base

softDeleteTz Migration method

Of the table structure builder softDeletesTz Method now takes the column name as the first parameter, and $precision Adjusted to the second parameter:

 /** * Add a "deleted at" timestampTz for the table. * * @param  string  $column * @param  int  $precision * @return \Illuminate\Support\Fluent */ public function softDeletesTz($column = 'deleted_at', $precision = 0)

ConnectionInterface contract

Illuminate\Contracts\Database\ConnectionInterface Contractual select and selectOne The method signature is updated to accommodate the new $useReadPdo Parameters:

 /** * Run a select statement and return a single result. * * @param  string  $query * @param  array   $bindings * @param  bool  $useReadPdo * @return mixed */ public function selectOne($query, $bindings = [], $useReadPdo = true); /** * Run a select statement against the database. * * @param  string  $query * @param  array   $bindings * @param  bool  $useReadPdo * @return array */ public function select($query, $bindings = [], $useReadPdo = true);

In addition, cursor Methods are also added to the contract:

 /** * Run a select statement against the database and returns a generator. * * @param  string  $query * @param  array  $bindings * @param  bool  $useReadPdo * @return \Generator */ public function cursor($query, $bindings = [], $useReadPdo = true);

If you implement this interface, you need to add this method to the implementation class.

SQL Server driver priority

Before Laravel 5.7, PDO_DBLIB The driver is used as the default SQL Server PDO driver, which has been considered abandoned by Microsoft, so in Larave 5.7, PDO_SQLSRV Will be used as the new default driver. In addition, you can also use PDO_ODBC Drive:

 'sqlsrv' => [ // ... 'odbc' => true, 'odbc_datasource_name' => 'your-odbc-dsn', ],

If both drivers are invalid, Larvel will use PDO_DBLIB Drive.

debugging

Dumper class

Removed Illuminate\Support\Debug\Dumper and Illuminate\Support\Debug\HtmlDumper Class to print classes using Symfony's native variables: Symfony\Component\VarDumper\VarDumper and Symfony\Component\VarDumper\Dumper\HtmlDumper

Eloquent

latest / oldest method

The Eloquent query builder's latest and oldest The method is updated to recognize the "created at" timestamp field that may be set to the Eloquent model class.

wasChanged method

The modification of Eloquent model will be triggered updated Before model event wasChanged Method. If you have questions about this, Can give us feedback

Floating point value specified by PostgreSQL

PostgreSQL now supports floating point values Infinity -Infinity and NaN Before Laravel 5.7, these values were converted to float double or real Will be converted into zero

In Laravel 5.7, these values will be converted into corresponding PHP constants INF -INF and NAN

Mailbox verification

If you choose to use the Mailbox Verification Service , need to add additional scaffolding code to the application, first, add VerificationController To app: App\Http\Controllers\Auth\VerificationController

You also need to verify the view stub file, which is located in resources/views/auth/verify.blade.php , you can GitHub warehouse View content in.

Finally, when the Auth::routes Method, you need to pass verify Options to methods:

 Auth::routes(['verify' => true]);

file system

Filesystem Contractual approach

Illuminate\Contracts\Filesystem\Filesystem Contract added readStream and writeStream method. If you implement this interface, you need to add these methods to the implementation class.

mail

Mailable dynamic variable style

Variables that are dynamically passed to the mail view can now Automatic conversion to hump style , which makes the behavior of mail dynamic variable and dynamic view variable consistent. Dynamic mail variable is not a Larravel feature that can be documented, so it has little impact on applications.

route

Route::redirect method

Route::redirect Method will now return when redirecting three hundred and two Status code, and permanentRedirect Method will return three hundred and one Status code:

 // Return a 302 redirect... Route::redirect('/foo', '/bar'); // Return a 301 redirect... Route::redirect('/foo', '/bar', 301); // Return a 301 redirect... Route::permanentRedirect('/foo', '/bar');

addRoute method

Illuminate\Routing\Router Class addRoute Method visibility from protected Adjust to public

verification

Nested validation data

In previous versions of Larravel, validate The method does not return correct data for nested validation rules, but it is modified in Laravel 5.7:

 $data = Validator::make([ 'person' => [ 'name' => 'Taylor', 'job' => 'Developer' ] ], ['person.name' => 'required'])->validate(); dump($data); // Prior Behavior... ['person' => ['name' => 'Taylor', 'job' => 'Developer']] // New Behavior... ['person' => ['name' => 'Taylor']]

Validator contract

Illuminate/Contracts/Validation/Validator Contract added validate method:

 /** * Run the validator's rules against its data. * * @return array */ public function validate();

If you implement this interface, you need to add this method in the implementation class.

miscellaneous

We also encourage you to check laravel/laravel Code warehouse Update log for. Although many of these updates are not necessary, you can keep these files in the application synchronized with the code repository. Some of these updates have been covered in this upgrade guide, but there are many other minor updates, such as configuration file or comment fine-tuning, which will not be pointed out one by one. You can GitHub comparison tool Easily view changes to select updates that are more important to you.


give the thumbs-up Cancel Like Collection Cancel Collection

<<Previous: New Features

>>Next: Contribution Guide