ATOM-Group's avatar

The new dd() in Laravel 5 is kind of shitty...

Back when it was a simple var_dump() that xdebug could parse for you, it would show you the fully expanded object graph (well, as deep as your xdebug configs were set - mine was set to 20 or so). This means I could verify the data I was getting back at a glance.

Now I have to click to expand every single collapsed item, and I can't seem to find any setting that forces it to always show up expanded. I have had to resort to using a browser script to force everything to be expanded for me.

Am I missing a setting somewhere, or is there a way to disable it and go back to the way it was?

Typical over-complicated less-than-user-friendly Symfony component >_<

/rant

0 likes
9 replies
Jeffberry's avatar

You can easily override the dd function with your own. If you rather have a simple var dump, just do so:

function dd()
{
    array_map(function($x) { var_dump($x); }, func_get_args());
    die;
}

You will need to put this somewhere where it gets defined before Laravel gets booted, else Laravel's will take effect. You could put it in bootstrap/app.php at the very top for example. I usually include a "helpers.php" at the very top of my app.php file in which I put things like this.

However, I use Kint personally: http://raveren.github.io/kint/ Best debugging tool out there :)

4 likes
Jeffberry's avatar

Or it seems you could simply just override the CSS and expand the sections by default

pre.sf-dump .sf-dump-compact {
    display: block !important;
}

I still recommend you check out Kint though!

Jeffberry's avatar

Yes, Kint is a fantastic tool. I use it on L5 and it works flawlessly. One of it's coolest features is that it uses Reflection to show you the available methods of an object if you dump an object, as well as the PHP Docs that go along with it.

One thing you may need to do is move Kint to the top of the autoload files for the same reason I told you that you need to define your custom dd before Laravel is booted, so that it's dd becomes effective and Laravel's is ignored.

In order to do that you will need to open the file /vendor/composer/autoload_files.php and you'll see an array of filenames. In that array look for the line that is including Kint:

    $vendorDir . '/raveren/kint/Kint.class.php',

All you need to do is move that entry in the array to the very top so that it's included first.

Give it a shot! It's real easy to use. If you look at their documentation you'll see they have some modifiers too. So by default it also outputs collapsed, but if you prefix your dd with an ! it will expand the output by default:

!d($variable)
Jeffberry's avatar

The correct way would be to extend \Illuminate\Support\Debug\HtmlDumper and add your custom styles there:

    protected $styles = array(
        'default' => 'background-color:#fff; color:#222; line-height:1.2em; font-weight:normal; font:12px Monaco, Consolas, monospace; word-wrap: break-word; white-space: pre-wrap; position:relative; z-index:100000',
        'num' => 'color:#a71d5d',
        'const' => 'color:#795da3',
        'str' => 'color:#df5000',
        'cchr' => 'color:#222',
        'note' => 'color:#a71d5d',
        'ref' => 'color:#a0a0a0',
        'public' => 'color:#795da3',
        'protected' => 'color:#795da3',
        'private' => 'color:#795da3',
        'meta' => 'color:#b729d9',
        'key' => 'color:#df5000',
        'index' => 'color:#a71d5d',
    );

In order to add in the CSS I suggested, you would add this to the bottom of that array:

'compact' => 'display: block !important'

However, then you would also need to extend \Illuminate\Support\Debug\Dumper and make it use your custom HtmlDumper. You would also need to override the dd function to make it use your custom \Illuminate\Support\Debug\Dumper. It seems it may take a little more than should be necessary to accomplish the custom CSS.

The quick/dirty/easy way would be to just override your dd function and throw it in there, remember that you would need to place this somewhere where it gets loaded before Laravel does.

function dd()
{
    if (PHP_SAPI !== 'cli')
    {
        echo "<style>pre.sf-dump .sf-dump-compact { display: block !important; }</style>";
    }

    array_map(function($x) { (new Dumper)->dump($x); }, func_get_args());

    die;
}
2 likes
sailingdeveloper's avatar

You can also use Cmd+Click on the arrow, and all of the items will expand :)

12 likes
Sinnbeck's avatar

To use with Kint with Laravel, simply install it using composer and then use:

ddd($array);
TimM1968's avatar

With kint now I needed "d($request()->all()); " to dump the request object. ddd didn't work.

Please or to participate in this conversation.