Laravel debugging Part 2 – Laravel Debugbar

Today we will continue on our series on Laravel debugging tools. In this article Laravel debugging with Laravel Debugbar we will talk about Laravel Debugbar.

What is laravel debugbar?

Laravel Debugbar  is a package which uses PHP Debug Bar with the Laravel Framework created by Barry vd. Heuvel. It’s help you catch error on your application in real time and you can see what’s going on in each step. You can see all the query executed by your application and so on without using var_dump or other related tools.

Installation

To install it you should have a working installation of laravel. If you do not have it just follow our article on laravel installation on the following link :

You simply install it by executing the following command :

composer require barryvdh/laravel-debugbar --dev

I add the --dev option to install it and use it only in local development. I guess you don’t want to show your user the query or debugging information about your application.

Laravel debugbar demo from laravelguy.com
Laravel debugbar

Laravel Debugbar by default uses lots of collectors to display necessary information but maybe you won’t need all. If your application start loading slow because of certain collector you can disable some of them. Here is the default collector enable by default :

  • PhpInfoCollector
  • MessagesCollector
  • TimeDataCollector
  • MemoryCollector
  • ExceptionsCollector

If you want to have more information about the collector available kindly check the github of the package.

Usage

If you think Laravel Debugbar is just the bar that showing information at the bottom your application then you are miss a lot. There’s many thing you can do with Debug bar. You can add message using the PSR-3 levels (debug, info, notice, warning, error, critical, alert, emergency):

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

You can mesure time of execution of a part of your code.

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

And a lot of more things that you can see in the documentation of the package by following the GitHub link

Conclusion

I think that bug is part of the coding of developing application. That’s why we should have good tools to help us avoid those errors and Laravel Debugbar fit in this category. Like other debug tools i talked about it in the previous part of this article i recommend Laravel Debugbar. Thanks for reading this article about Laravel debugging with Laravel Debugbar as usual if you got any trouble while install it, leave a comment and i will try to help you.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *