How to get unfolded array in browser with dump in Laravel (by default)

121 Views Asked by At

how can I make laravel dump output the contents of a multidimensional array to the browser immediately in the expanded state (not folded)? I know I can Ctrl+Click, but I want the array to be expanded by default. I probably need to set up a Var-dumper. But how do I do that in Laravel?

I've tried something, but nothing worker out

use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\CliDumper;

$cloner = new VarCloner();
$dumper = new CliDumper();
$cloner->setMaxItems(-1);
$cloner->setMinDepth(1000);
$cloner->setMaxString(10000);
$dumper->dump($cloner->cloneVar(['one', 'two', 'three' => ['one', 'two']]));
dump(['one', 'two', 'three' => ['one', 'two']]);
1

There are 1 best solutions below

0
Rey Arlena On

Unfortunately this isn't in Laravel, but you can use Tampermonkey (browser extension) to do this as-per this post.

Install Tampermonkey > Click Extension icon > Create New Script > Change @match below to match your domain(s) > Save. Reload your page and you should be good to go - I have tested using your code and it works well.

// ==UserScript==
// @name         Expand `dd` Symfony's VarDumper Component
// @description  see: https://laracasts.com/discuss/channels/general-discussion/expanding-dd-vardumper-by-default
// @author       curtisblackwell
// @match      https://your-domain.test/
// ==/UserScript==

(function() {
    'use strict';
    var compacted = document.querySelectorAll('.sf-dump-compact');

    for (var i = 0; i < compacted.length; i++) {
        compacted[i].className = 'sf-dump-expanded';
    }

})();