Originally published on laravel.learnio.dev — part of the Laravel best practices course. View this lesson on the original site.

In this lesson

Debugging in Laravel works best when you follow a repeatable path: reproduce, inspect, narrow scope, fix, and verify.

A practical debugging loop

  1. reproduce the bug reliably,
  2. identify where it fails (route, controller, query, view),
  3. inspect values and logs,
  4. apply a small fix,
  5. verify with the original failing path.
flowchart LR
  A[Reproduce bug] --> B[Collect evidence]
  B --> C[Find failing layer]
  C --> D[Apply focused fix]
  D --> E[Retest]

Use dd, dump, and logs intentionally

  • dd($value) dumps and stops execution, useful when you need a hard stop.
  • dump($value) dumps without stopping, useful inside loops.
  • logger()->info(...) writes structured debug context to your logs.

Example:

public function show(string $id)
{
    logger()->info('Loading order', ['order_id' => $id]);

    $order = Order::find($id);
    dump($order?->status);

    if (! $order) {
        abort(404);
    }

    return view('orders.show', ['order' => $order]);
}

Read Laravel errors and stack traces

With APP_DEBUG=true in local development, Laravel shows detailed exception pages with stack traces. Use them to find:

  • the failing line,
  • the exception type,
  • the first application frame in your code.

In production, keep APP_DEBUG=false and use logs and monitoring instead.

Check database behaviour when results look wrong

If data is missing or incorrect, inspect the query path:

  • confirm filter values from request input,
  • check model scopes and casts,
  • verify rows directly in the database,
  • watch query timing and SQL via tooling like Telescope.

A lot of "controller bugs" are actually query assumptions.

Install Debugbar and Telescope

Use these in local development to see what Laravel is doing under the hood.

Laravel Debugbar (quick request-level debugging)

Best for seeing SQL queries, timings, views, and request details for the current page.

Install it:

composer require --dev barryvdh/laravel-debugbar

After install, reload your app and you should see the Debugbar panel at the bottom of the page.

Laravel Telescope (full app activity dashboard)

Best for deeper inspection across requests, jobs, logs, exceptions, cache, and dumps.

Install it:

composer require --dev laravel/telescope
php artisan telescope:install
php artisan migrate

Open it at:

/telescope

Telescope is heavier than Debugbar, so treat it as a local or controlled environment tool.

Common first-pass checks

  • run php artisan route:list to confirm route and method,
  • verify .env values for database and app URL,
  • clear stale config cache if env values changed:
php artisan config:clear
php artisan cache:clear

Keep debugging safe in team environments

  • never leave dd() in committed code,
  • avoid logging secrets or full tokens,
  • log IDs and state transitions instead of sensitive payloads,
  • keep APP_DEBUG=false outside local development.

The goal is not just to fix one issue, but to leave better signals for the next issue.

From Laravel best practices — What is Laravel?