|
| 1 | +--- |
| 2 | +name: debug-using-debugbar |
| 3 | +description: > |
| 4 | + Use this skill to optimize requests or debug Laravel application issues — slow pages, N+1 queries, exceptions, |
| 5 | + failed requests, or unexpected behavior — by inspecting data captured by Laravel Debugbar via |
| 6 | + Artisan CLI commands. Use when the user asks to investigate a bug, diagnose a slow request, |
| 7 | + find duplicate queries, check what happened on a previous request, or optimize database |
| 8 | + performance, even if they don't explicitly mention "debugbar" or "profiling." |
| 9 | +compatibility: Requires Laravel with fruitcake/laravel-debugbar installed and debug mode enabled. |
| 10 | +--- |
| 11 | + |
| 12 | +## Debugging and optimizing workflow |
| 13 | + |
| 14 | +1. Find the relevant request: |
| 15 | + ```bash |
| 16 | + php artisan debugbar:find --issues --max=50 |
| 17 | + ``` |
| 18 | +2. Inspect the request summary to identify which collectors have data: |
| 19 | + ```bash |
| 20 | + php artisan debugbar:get {id} |
| 21 | + ``` |
| 22 | +3. Drill into the relevant collector based on the issue type: |
| 23 | + ```bash |
| 24 | + php artisan debugbar:get {id} --collector=exceptions |
| 25 | + ``` |
| 26 | +4. For query issues, use dedicated query analysis: |
| 27 | + ```bash |
| 28 | + php artisan debugbar:queries {id} |
| 29 | + ``` |
| 30 | +5. Trace the problem to source code using backtraces, then fix and re-test. |
| 31 | + |
| 32 | +## Finding requests |
| 33 | + |
| 34 | +```bash |
| 35 | + |
| 36 | +# List recent requests (shows summary with status, duration, memory, query count) |
| 37 | + |
| 38 | +php artisan debugbar:find |
| 39 | + |
| 40 | +# Filter by URI pattern (fnmatch) and/or HTTP method |
| 41 | + |
| 42 | +php artisan debugbar:find --uri="/api/*" --method=POST |
| 43 | + |
| 44 | +# Only show requests with issues (exceptions, slow queries, duplicates, errors) |
| 45 | + |
| 46 | +php artisan debugbar:find --issues --max=50 |
| 47 | + |
| 48 | +# Customize issue thresholds (defaults: --min-queries=50, --min-duration=1000, --min-duplicates=2) |
| 49 | + |
| 50 | +php artisan debugbar:find --issues --min-queries=10 --min-duration=500 |
| 51 | + |
| 52 | +# Threshold options also work standalone, filtering on just that criteria |
| 53 | + |
| 54 | +php artisan debugbar:find --min-queries=20 |
| 55 | +``` |
| 56 | + |
| 57 | +`--issues` flags: exceptions, non-2xx status, high query count, slow queries, duplicate query groups, slow request duration, and failed queries. Issue filtering applies on top of the fetched result set — increase `--max` to scan further back. |
| 58 | + |
| 59 | +## Inspecting a request |
| 60 | + |
| 61 | +```bash |
| 62 | + |
| 63 | +# Summary of all collectors (available collectors depend on config) |
| 64 | + |
| 65 | +php artisan debugbar:get latest |
| 66 | +php artisan debugbar:get {id} |
| 67 | + |
| 68 | +# Full data for a specific collector |
| 69 | + |
| 70 | +php artisan debugbar:get {id} --collector=exceptions |
| 71 | +``` |
| 72 | + |
| 73 | +Pick the collector by issue type: |
| 74 | +- **Error/500** → `exceptions` · **Slow page** → `queries`, `time` · **Auth** → `auth`, `gate` · **Cache** → `cache` |
| 75 | + |
| 76 | +## Analyzing queries |
| 77 | + |
| 78 | +```bash |
| 79 | + |
| 80 | +# Overview with duplicate detection and slow query flags |
| 81 | + |
| 82 | +php artisan debugbar:queries {id} |
| 83 | + |
| 84 | +# Backtrace and params for a specific statement |
| 85 | + |
| 86 | +php artisan debugbar:queries {id} --statement=N |
| 87 | + |
| 88 | +# EXPLAIN plan or re-execute a SELECT |
| 89 | + |
| 90 | +php artisan debugbar:queries {id} --statement=N --explain |
| 91 | +php artisan debugbar:queries {id} --statement=N --result |
| 92 | +``` |
| 93 | + |
| 94 | +Duplicate queries are a strong N+1 signal. Use `--statement=N` to get the backtrace and find the origin. |
| 95 | + |
| 96 | +## Gotchas |
| 97 | + |
| 98 | +- Always start with `debugbar:find --issues` rather than `debugbar:find` — the issue flags surface the most actionable requests immediately. |
| 99 | +- The `{id}` is the request ID from the `debugbar:find` output, or use `latest` to inspect the most recent request. |
| 100 | +- Collector availability depends on the app's debugbar config — the summary from `debugbar:get` shows which collectors have data. |
| 101 | +- `--explain` and `--result` only work on SELECT queries. They re-execute against the current database, so results may differ from the original request. |
| 102 | +- `debugbar:clear` removes all stored data — use it to reset between debugging sessions, not mid-investigation. |
0 commit comments