Skip to content

Laravel 5.5 – DD and Dump in Collections

Last updated on February 17, 2018

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();
 $users->dump()
           ->sortBy('created_at')
           ->dump()
           ->take(10)
           ->pluck('name')
           ->dd() // here dd will dump the resulst and stops the execuation. 
           ->take(1);

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)

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments