Laravel 5 Collections: Dumping the Collection Contents and Continuing Script Execution for Debugging With dump

April 22, 2018 —John Koster

The dump method is similar to the dd method in that it is used to dump the contents of the collection to the output for debugging purposes, however, unlike the dd method, the dump method will not stop execution of the script. Because of the behavior of the dump method, its behavior is very similar to PHP's var_dump function.

#Signature

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

#Example Use

The following example demonstrates the behavior of the dump method:

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

The above example would produce output similar to the following:

1Collection {
2 #items: array:1 [
3 "key" => "value"
4 ]
5}
6This will be visible in the output

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.