Posted by Arjun on Wednesday 29th November 2017

Laravel 5.5 - DD and Dump in Collections

Laravel 5.x Laravel 5.5 Dump Collections

Laravel offers two new useful debugging methods dump() and dd() as part of Laravel 5.5 version release. These methods are added to Collections, it means you can call dump() and dd() on collection instances.

In previous Laravel versions, when debugging collections we’d assign a variable to a collection then keep dumping the variable as we altered the collection. This won’t be the case anymore in Laravel 5.5 as we can now call dd() or dump() directly on a collection instance. These methods are making debugging a lot easier and simple.

Imagine you had a collection of users which went through a series of transformations and we wanted to inspect the collection at each step, then this will do:

Using dump()

$users= Users::all();
           ->dd() // here dd will dump the resulst and stops the execuation. 

Output :

NOTE: There is a difference between calling dump() and dd() on a collection. dump() outputs the results at that moment and then continues processing while dd() stops the process immediately and dumps out the results (dd stands for dump and die)