Laravel 5.6 – Debugging with dump and dd Functions
In this article, we will discuss how can we handle Laravel Debugging. Laravel offers two effective and useful debugging methods dd() and dump(). As we know, Laravel provides rich features to fulfill our minor to complex requirements. I’m assuming you are familiar with the Laravel framework if not then you can start with given tutorials.
- Laravel Setup
- Laravel Default Authentication Setup
- Understanding Laravel Middleware
- All You Need to Know Laravel Routing
- Setup Virtual Host with Xampp Server
Method dd() and dump()
In previous Laravel versions, when we debug collections then we assign a variable to a collection then keep dumping the variable as we altered the collection.
$posts = Post::where('status','published')->get(); dd($posts); // Here dd() will dump the resultset and stop the execution.
In Laravel 5.5, we can call dd() or dump() directly on a collection instance. These methods are making debugging a lot easier. For example: assume we had a collection of posts which went through a series of transformations and we wanted to inspect the collection at each step, then this will do:
$posts = Post::all(); $posts->dump() ->sortBy('created_at') ->dump() ->take(10) ->pluck('post_title') ->dd() // here dd will dump the resulst and stops the execuation. ->take(1);
Difference between dd() and dump()
Both function used for debugging. But having one difference. dump() output the results and then continues processing. dd() output the results and stops the process immediately (dd stands for dump and die).
Hope you like this post. Please feel free to add the comment below if any query.
If you like our content, please consider buying us a coffee.
Thank you for your support!
Buy Me a Coffee