How to Debug in Laravel
Thank you for your continued support.
This article contains advertisements that help fund our operations.
A practical guide to debugging in Laravel, covering dd(), dump(), logging, tinker, and Laravel Telescope.
What Is Debugging?
Debugging means finding a bug in your program and fixing it so the code works correctly.
Laravel ships with several handy tools that make this process much easier. Here are the debugging methods I actually use in day-to-day development.
Debugging in Blade Views (Non-API)
In most cases, the dd() function is all you need.
What Does dd() Do?
It stops execution right where it's called and lets you inspect the contents of a variable.
Stopping Execution with dd() Narrows Down Where the Error Is
Because dd() halts execution and dumps the variable's contents, it lets you pinpoint exactly where something is going wrong.
Instead of blindly editing code inside a function, knowing precisely which line is responsible makes debugging much faster.
If the error still appears even after placing dd() right after the suspected line, you know the real cause is earlier in the code.
Using dd() in a Controller
$users = User::all();
dd($users);
// Result
// Illuminate\Database\Eloquent\Collection {#1039 ▼
// #items: array:6 [▶]
// }dd() vs. dump()
dd() halts execution, but if you don't want that, use dump() instead — it prints the variable's contents while letting the rest of the code keep running.
$users = User::all();
dump($users);
// Execution continuesYou can also pass multiple variables at once, like dd($a, $b, $c), to inspect them all in one go.
Using dd() in a Blade View
You can use it the same way inside a Blade file.
{{-- Blade file --}}
{{ dd($users) }}In a Blade file, everything up to the point where execution stops has already been rendered, so the page will appear partially loaded.
Debugging APIs
Checking Error Details
By default, error details are written to:
storage/logs/laravel.logThe most recent entries appear at the bottom.
Debugging Variables: Method 1 — Return It as the Response
The simplest approach is to return the variable you want to inspect directly as the response.
Since nothing after return executes, this narrows down the bug's location just like dd() does.
$users = User::all();
return response()->json(compact('users'), 200);
// Nothing below this line runs
$posts = Post::someBuggyMethod();This lets you see exactly what $users contains at that point in the request.
Debugging Variables: Method 2 — Write It to the Log
If you want to check a variable's contents without halting execution, logging it is a convenient option.
\Log::info($users);This writes the variable's contents to the log file.
You can then check storage/logs/laravel.log to see what was logged.
A Few Other Tools Worth Knowing
php artisan tinker— an interactive shell for trying out Eloquent queries and logic from the command line. Great for quick checks.- Laravel Telescope — a debugging package that gives you a dashboard of requests, queries, exceptions, and more. Installing it in your local environment saves a lot of time you'd otherwise spend digging through log files by hand.
Summary
That covers the debugging methods I use most often in Laravel.
When working on APIs, I'd also recommend pairing this with an API client like Postman to make checking responses easier.





