Skip to content

Instantly share code, notes, and snippets.

@vkuzmov
Created March 6, 2017 12:30
Show Gist options
  • Save vkuzmov/d69eed705268aaf771ebdc0725f3d1a6 to your computer and use it in GitHub Desktop.
Save vkuzmov/d69eed705268aaf771ebdc0725f3d1a6 to your computer and use it in GitHub Desktop.
Laravel - automatically expand strings printed with dd()
<?php
// PUT THIS IN bootstrap/autoload.php (at the end)
/** auto-expand DD */
function dd()
{
array_map(function ($x) {
(new Illuminate\Support\Debug\Dumper)->dump($x);
}, func_get_args());
// Added to auto-expand dd() output
if (PHP_SAPI !== 'cli') {
echo "<script>
var tg = document.querySelectorAll('.sf-dump-str.sf-dump-str-collapse');
[].forEach.call(tg, function(item) {
item.className = 'sf-dump-str sf-dump-str-expand';
item.querySelector('.sf-dump-str-toggle').remove();
});
</script>";
}
die(1);
}
@monmonja
Copy link

with laravel 5.8 i did this

{
  array_map(function ($x) {
    $cloner = new \Symfony\Component\VarDumper\Cloner\VarCloner();
    $cloner->setMaxItems(-1); // Specifying -1 removes the limit
    $dumper = 'cli' === PHP_SAPI ? new \Symfony\Component\VarDumper\Dumper\CliDumper() : new \Symfony\Component\VarDumper\Dumper\HtmlDumper();
    $dumper->dump($cloner->cloneVar($x));
  }, func_get_args());
  // Added to auto-expand dd() output
  if (PHP_SAPI !== 'cli') {
    echo "<script>
			var tg = document.querySelectorAll('.sf-dump-compact');
			[].forEach.call(tg, function(item) {
				item.className = 'sf-dump-expanded';
				
			});
			document.querySelectorAll('.sf-dump-ref.sf-dump-toggle').forEach((i) => i.remove());
		</script>";
  }
  die(1);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment