Create New Post

Laravel - Dump Server

Laravel's "dump server" is a development tool that allows you to dump information to the console or a browser's JavaScript console during the execution of your code. It can be helpful for debugging and inspecting variables at runtime.

Here's how you can use Laravel's dump server:

Installation

To use the dump server, you need to install it via Composer. Open your terminal and run the following command:

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

Register Service Provider (Laravel 5.4 and below)

If you are using Laravel version 5.4 or below, you'll need to add the service provider to your config/app.php file:

'providers' => [
    // ...
    BeyondCode\DumpServer\DumpServerServiceProvider::class,
],
 

Starting the Dump Server

Once the package is installed, you can start the dump server using the following Artisan command:

php artisan dump-server 

This command will start the dump server on port 9912. You can access the dump server panel by visiting http://localhost:9912 in your browser.

Dumping Variables

In your code, you can use the dump function to output information to the dump server. For example:

dump($variable); 

This will display the variable's contents in the dump server's panel.

Dumping to Browser Console

If you want to dump information directly to the browser's JavaScript console, you can use the dd (dump and die) function:

dd($variable);

This will halt the execution of the script and output the variable to the browser console.

Additional Configuration

You can configure the dump server in your config/dump-server.php file. For example, you can change the host and port settings.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

28065