Laravel 5 Collections: Dumping the Collection Contents and Stopping Script Execution for Debugging With dd

April 22, 2018 —John Koster

The dd method will dump the contents of the collection and stop execution of the script; in this way, it works just like the global dd helper function except that it acts exclusively on the collections internal array.

#Signature

1public function dd(
2 ...$args
3);

#Example Use

In the following example, we will create a collection and dump its content to the screen and stop execution of the script. The last echo statement should not be visible in the browser or terminal output:

1$collection = collect([
2 'key' => 'value'
3]);
4 
5$collection->dd();
6 
7echo 'This should not be visible in the output';

If viewed in a browser, the previous example would output:

1array:1 [
2 "key" => "value"
3]

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.