Introduction of new features of Laval 5.7 Laval Dump Server expansion package facilitates local development code debugging


At Laracon US 2018, Taylor Otwell announced that it would be introduced in Laravel 5.7 Laravel Dump Server Expansion package (this expansion package introduces Symfony's Var Dump Server into Laval for collection in the development environment dump() Function output, and print it to the console or export it to a file), as a development environment dependency composer.json Filed require-dev In configuration items:

 "require-dev": { "beyondcode/laravel-dump-server": "~1.0", "filp/whoops": "^2.0", "fzaninotto/faker": "^1.4", "mockery/mockery": "^1.0", "nunomaduro/collision": "^2.0", "phpunit/phpunit": "^7.0" },

In this way, you can use the following Artisan commands to output print data to the console or HTML file without opening the browser in the Laravel 5.7 application:

 php artisan dump-server # Or send the output to an HTML file php artisan dump-server --format=html > dump.html

The above command will start the Web server in the background and listen dump() Function, and then send the output to the console/export to a file. If the above command is not run on the console, then dump() The function is executed by default and will not be affected.

Larvel will continue to introduce some useful third-party expansion packs into the official release, for example, in Larvel 5.6 nunomaduro/collision , introduced in Larravel 5.5 fideloper/proxy

If you want to use the Laval Dump Server in Laval 5.6 and below, you need to install this expansion package through Composer:

 composer require --dev beyondcode/laravel-dump-server

If you want to customize it, you can publish its configuration file to config Under the directory:

 php artisan vendor:publish --provider=BeyondCode\\DumpServer\\DumpServerServiceProvider

The command will config Add one next debug-server.php Configuration file. You can configure the IP address and port number of the server you want to listen to in this configuration file. If Laradock is used as the local development environment, you need to replace the IP address with the container name of the workspace before normal use.

The use of this expansion pack is also very simple routes/api.php Define an API route in the file:

 Route::get('/test', function (Request $request) { dump($request->all()); return [ 'name' => $request->get('name') ? : ' Academician ', 'site' => $request->get('site') ? : ' Laravel College ', ]; });

If not enabled php artisan dump-server Commands, accessing http://dump-server.test/api/test?name= College&site=Laravel College The page is shown as follows:

Run the command under the project root directory, visit the URL link above again, and you will see dump() The output is printed to the console:

 laravel dump server

At the same time, it is no longer displayed in the browser dump() Output, but output the returned array in JSON format:

With this extension package, we can call the dump() The function prints data without affecting the original code execution, thus greatly improving the efficiency of local development and debugging.


give the thumbs-up Cancel Like Collection Cancel Collection

<<Previous: Optimization of new features of Laravel 5.7 Error messages caused by dynamic call to Eloquent model

>>Next: The new URL generation syntax in the new feature series of Larravel 5.7