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
dd() command is what I grab, but being able to dump output at certain points without
die()ing seems like an excellent workflow!
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):
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.
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 us BotMan 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:
Source link https://laravel-news.com/laravel-dump-server