Debugbar and dd

Contents
dd() stops
dump() continues
Debugbar concept
Spot N+1 early

dd() stops

dd means dump and die: it prints a variable in readable form and stops the request right there. Drop it into a controller when the code path confuses you, reload the page, read the output, then delete the line before you commit.

Because dd ends the request, lines below it never run. That property makes it a sharp scalpel for one question at a time: what does this variable hold at this exact point.

$userId = 7; dd($userId); echo "This line never runs";

dump() continues

dump prints the same readable output but lets the request finish. Use it when you want to compare several values across one page, for example the raw input and the validated copy side by side.

$name = "Ada"; dump($name); echo "The page still renders";

Debugbar concept

Debugbar is a development toolbar that sits at the bottom of your pages and counts what the request did: queries, views, route name, and timing. It never ships to production - it is a local lens for spotting waste early.

Debugbar panels to watch queries: every SQL statement and its time timeline: where the milliseconds went views: which templates rendered route: which route answered

Spot N+1 early

The classic N+1 problem hides in innocent loops: one query loads the list, then each row fires one more query for its relation. Debugbar shows the count climbing with the list size, which is the signature of this bug.

$posts = Post::all(); foreach ($posts as $post) { echo $post->author->name . "\n"; }

Ten posts run eleven queries here: one for the list plus one author lookup per row. Lesson 48 fixes it with a single eager load, but train your eyes now: loops plus relations deserve a second look.

Next: Broadcasting

Article author: Arthur Isaev

Related articles
Development with PHP
What is Laravel and where it runs
Install Laravel
Your first route
Controllers
Blade basics
Blade advanced
Migrations
Eloquent models
Relationships
Query builder
Seeders and factories
Validation
Auth intro
Hand-rolled login
Middleware
Service container
Config and env
Artisan commands
Events and listeners
Queues
Mail
Cache
Sessions in Laravel
CSRF
Hashing
Sanctum tokens
API resources
Gates and policies
Notifications
Scheduler
Filesystem
Localization
Testing
HTTP tests
Collections
Carbon dates
Pagination
File uploads
Eloquent advanced
Transactions and locks
Deployment
Debugbar and dd
Broadcasting
Full-text search
Capstone: blog
Capstone: JSON API
Capstone: shop cart
Performance: kill N+1
Modern Laravel tour
Hero roadmap: the whole course on one page
Banner image

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.com
Write to info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: