Debug Your App with the Laravel Debugbar

Published on by

Debug Your App with the Laravel Debugbar image

The Laravel Debugbar by Barry vd. Heuvel is a package that allows you to quickly and easily keep tabs on your application during development. With a simple installation and powerful features, the Debugbar package is one of the cornerstone packages for Laravel.

The debugbar is already updated for Laravel 5 and I wanted to show you all the great features it includes.

Installing the Laravel Debugbar

Installation is extremely simple. I was about to have it running in under five minutes, and four of those was waiting on composer. Here are the steps to get it setup and going.

In your Laravel 5 project require the package:

composer require barryvdh/laravel-debugbar

Next open config/app.php and inside the ‘providers’ array add:

'BarryvdhDebugbarServiceProvider',

Finally, if you wish to add the facades add this to the ‘aliases’ array:

'Debugbar' => 'BarryvdhDebugbarFacade',

Now as long as your app is in debug mode the bar will already be loading showing some nice stats about the page you are viewing.

Getting to know debugbar

You have the user interface of the debugbar mastered in a few short minutes and it’s really powerful. Let’s look at all the default settings that are included:

Messages

Messages is a special section, it’s only loaded by calling the facade from within your code.

Debugbar::info($object);
Debugbar::error('Error!');
Debugbar::warning('Watch out…');
Debugbar::addMessage('Another message', 'mylabel');

The messages include the PSR-3 levels (debug, info, notice, warning, error, critical, alert, emergency)

Timeline

The timeline is perfect for fixing the bottlenecks in your code. Here are a few examples available:

Debugbar::startMeasure('render','Time for rendering');
Debugbar::stopMeasure('render');
Debugbar::addMeasure('now', LARAVEL_START, microtime(true));
Debugbar::measure('My long operation', function() {
// Do something…
});

Exceptions

The next tab is an exceptions logger. You can log exceptions to the debugbar by using code like this:

try {
throw new Exception('foobar');
} catch (Exception $e) {
Debugbar::addException($e);
}

Views

Views will show you all the templates rendered as well as include all the parameters passed into them. This is really handy as your application grows and you have numerous views. With this, you can be sure you are sending just the data your view actually needs, and lots of other use cases.

Route

Magically see everything related to the route being called. The URI, controller, file path, and namespace.

Queries

Queries are one of the important parts for a lot of apps. I’ve seen apps not utilize eager loading and end up with a huge number of queries.

To give you a real world example I was tasked with building a back office style report for an e-commerce system. I was able to get the report working on my dev machine with seed data but as soon as I seeded real data the page took 20+ seconds to load. Browsing the queries tab in debugbar showed me exactly where my problem was.

Mail and Request

These two include everything you need to know about emails going out and the current request.

Folder Icon

I’m not sure the “real” name for this, but by clicking the folder icon you can see all previous requests. This is useful when performing ajax calls so you can get more information on the actual requests.

Going Further

In this post, I only outlined the basics of what the Laravel Debugbar includes. It has many more features under the hood including twig integration, enabling/disabling at runtime, and bridge collectors. If you want to go further the docs cover a lot of the underlying code in more details.

This is a package I highly recommend.

Eric L. Barnes photo

Eric is the creator of Laravel News and has been covering Laravel since 2012.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

Laravel Forge logo

Laravel Forge

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Forge
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $7500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Bacancy logo

Bacancy

Supercharge your project with a seasoned Laravel developer with 4-6 years of experience for just $2500/month. Get 160 hours of dedicated expertise & a risk-free 15-day trial. Schedule a call now!

Bacancy
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
Lunar: Laravel E-Commerce logo

Lunar: Laravel E-Commerce

E-Commerce for Laravel. An open-source package that brings the power of modern headless e-commerce functionality to Laravel.

Lunar: Laravel E-Commerce
LaraJobs logo

LaraJobs

The official Laravel job board

LaraJobs
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Rector logo

Rector

Your partner for seamless Laravel upgrades, cutting costs, and accelerating innovation for successful companies

Rector
MongoDB logo

MongoDB

Enhance your PHP applications with the powerful integration of MongoDB and Laravel, empowering developers to build applications with ease and efficiency. Support transactional, search, analytics and mobile use cases while using the familiar Eloquent APIs. Discover how MongoDB's flexible, modern database can transform your Laravel applications.

MongoDB

The latest

View all →
Add Comments to your Laravel Application with the Commenter Package image

Add Comments to your Laravel Application with the Commenter Package

Read article
Laravel Advanced String Package image

Laravel Advanced String Package

Read article
Take the Annual State of Laravel 2024 Survey image

Take the Annual State of Laravel 2024 Survey

Read article
Upload Files Using Filepond in Livewire Components image

Upload Files Using Filepond in Livewire Components

Read article
The Best Laravel Tutorials and Resources for Developers image

The Best Laravel Tutorials and Resources for Developers

Read article
Introducing Built with Laravel image

Introducing Built with Laravel

Read article