Laravel Debugbar: debug your Laravel 5 app in the browser

The Laravel debug toolbar is a package written by Barry vd. Heuvel that lets you keep an eye on your application while you are developing it. It installs in minutes. Here is how to set it up and what each tab of the bar tells you.

Laravel Debugbar: debug your Laravel 5 app in the browser

The Laravel debug toolbar is, first and foremost, a package written by Barry vd. Heuvel that lets you keep an eye on your application quickly and easily while you are developing it. It installs in minutes and belongs to the handful of packages worth knowing about.

Installing the package

Installing the Laravel debug toolbar is fairly simple. We start with Composer and run the composer require command to download the package.

bash
composer require barryvdh/laravel-debugbar

Then open the config/app.php file and add this inside the Providers array:

php
Barryvdh\Debugbar\ServiceProvider::class,

Next, add its alias to the Facades array:

php
'Debugbar' => Barryvdh\Debugbar\Facade::class,

And finally, do not forget to run the following command:

php
php artisan vendor:publish --provider="Barryvdh\Debugbar\ServiceProvider"

That is it, the Laravel debug toolbar is installed. As long as your application is in debug mode, the bar shows up and displays some useful statistics about the page you are looking at.

A tour of the options

Here is what the toolbar looks like:

laravel-debugbar-01.jpg

Message

Messages is the section that displays the messages or the tests you have put in a controller, a model, and so on.

php
Debugbar::info("Message info !");
Debugbar::error('Message erreur!');
Debugbar::warning('Attention !');
Debugbar::addMessage('Mon Message', 'Mon Label');

Messages cover the PSR-3 levels (Emergency, Alert, Critical, Error, Warning, Notice, Info, Debug).

Timeline

debug-laravel-02.jpg

The Timeline is handy for fixing code that holds back the performance of your application. Here are a few examples:

php
Debugbar::startMeasure('render','Temps du rendu');
Debugbar::stopMeasure('render');

Debugbar::addMeasure('Lancement Laravel', LARAVEL_START, microtime(true));
Debugbar::measure('Total Utilisateurs', function() {
    $user = App\User::all();
});

Exceptions

The next tab records exceptions. You can log exceptions and have them show up in the debug bar:

debug-laravel-3.jpg

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

Views

debug-laravel-07.jpg

Views shows you every parent and child template along with all the parameters passed to them. With this tab you can make sure you are only sending the data you actually need:

php
return view('welcome')->with('titre', 'Mon Titre')->with('message', 'Mon Message');

Route

debug-laravel-05.jpg

Not much to say here, it speaks for itself. Route covers everything to do with your route: its controller, the URI used, its prefix, its namespace and so on.

Query

debug-laravel-06.jpg

Queries are one of the most important parts of an application, and this tab is where you find everything about the queries you send to your database server. Badly optimised or unwanted queries can really drag out your page loads and hurt your users.

Mail and Request

These two cover everything you need to know about outgoing emails and about requests.

···

LaravelPackages

Damien Flandrin Web developer since 2010, creator of Gekkode and Email Impact. Every article is tested on a real project before publication. Contact
Newsletter

New tests, tutorials and projects, by e-mail.

Reproducible tests, versioned code, dated results. Never any spam.