Laravel 5.5 – DD and Dump in 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()

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)

By Arjun

I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.

Leave a Reply

Your email address will not be published. Required fields are marked *