53

Laravel Dump Server

 5 years ago
source link: https://www.tuicool.com/articles/hit/NNbqQb7
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Laravel Dump Server is a package by Marcel Pociot, which brings Symfony’s Var-Dump Server to Laravel.

Instead of dumped data messing up the response, a dedicated “Dump server” console collects dumped data which is sent to stdout, or piped to a file:

# Symfony Example >= Symfony 4.1
./bin/console server:dump

# Artisan example using the Laravel Dump Server package
php artisan dump-server

The dd() command is what I grab, but being able to dump output at certain points without die() ing seems like an excellent workflow!

2EZnA3j.png!web

After I learned about this package, I submitted a pull request to support HTML output which you can pipe to an HTML file instead. If the pull request is accepted, you could specify the HTML output format which is pretty neat in my opinion:

php artisan dump-server --format=html > dump.html

After piping the output to dump.html , you can continue to refresh your application and get updated output in the HTML file that you can see by refreshing. The example output would look like this (notice that the Illuminate HtmlDumper class is used to give the output the Laravel treatment):

bqAJFzR.png!web

Please note that piping to HTML isn’t available at the time of writing, but I’ll update this post if the HTML formatting option is accepted.

How Does this Work?

In the background, Symfony provides a dedicated server to collect dumped data via DumpServer . When you call dump in your application code while the server is running, the dumped data is sent to the centralized server that outputs to the console.

When the dump server is not running, dump() works just like you’d expect by default.

Learn More

You can learn more about and download the Laravel Server Dumper package on GitHub. Star the package and share it with your friends.

If you love Laravel, you should support Marcel Pociot in his open-source efforts in any way you can! He’s putting out some quality work, plus has given usBotMan to help make developing chatbots a breeze with your favorite tools.

Over the last couple of weeks, Marcel has been on Laravel News four times, with open-source and Laravel-specific contributions:

Bravo!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK