Laravel dd() not showing Dump as HTML

I recently ran into an issue where the Laravel dd() Helper did not show anything, what the heck?

Laravel dd() not showing Dump as HTML
29 Jan 2025
|
2 min read
|
1 Comment

I recently ran into an issue where the Laravel dd() helper function did not display anything to my browser when calling it in any place and simply responded with a HTTP 500 and literally 0 bytes of body.

I was digging around and found out that spatie/ignition - the pretty error pages you'll see on unhandled Exceptions - will replace the Synfony VarDumper Handler with a kind of middleware that collects all dumps (and displays them when another Exception is thrown? idk).

Well, how to get it working again?

Define a new environment variable VAR_DUMPER_FORMAT inside your project.

VAR_DUMPER_FORMAT=any

The value any isn't actually defined an can be replaced by any gibberish text. There are some special cases:

  • html: Always display the dump as HTML - also in CLI applications

  • cli: Always display the dump in CLI format

  • server: Dumps via a remote connection, only server actually just dumps to HTML or CLI based on the runtime

  • tcp://...: Dumps to a remote server via TCP

Details

Inside the VarDumper class, a setHandler method used by Laravel-Ignition will check if the previously mentioned environment variable is set and prevents overriding the existing handler.

public static function setHandler(?callable $callable): ?callable
{
    $prevHandler = self::$handler;

    // Prevent replacing the handler with expected format as soon as the env var was set:
    if (isset($_SERVER['VAR_DUMPER_FORMAT'])) {
        return $prevHandler;
    }

    self::$handler = $callable;

    return $prevHandler;
}

Comments

Read more...