How to Debug Laravel 4
Laravel 3 had a profiler integrated, but it was removed when Laravel launched version 4. This was a useful feature, so when it was removed, we were disappointed. Fortunately, a new package has been developed to fill the void that was left: The Laravel Debugbar. This makes it simple to debug Laravel.
Installation
Make sure that your composer.json
file is configured properly:
"require-dev": {
"barryvdh/laravel-debugbar": "1.*"
}
You’ll notice that we put it in our "require-dev"
block; since we don’t want the Debugbar in production, we add it to the development group of dependencies. Next, add the following Service Provider to the providers array in the app/config/app.php
file: 'Barryvdh\Debugbar\ServiceProvider',
.
Because this package relies on a lot of JavaScript and CSS to render the debugbar, you’ll need to publish the assets for this package by running $ php artisan debugbar:publish
.
Getting this far enables the profiler, and that shows you stuff about your current route, recent queries, etc. It would be really useful, though, if you could log stuff to a place where you can reference it while you work. Fortunately, this is possible when you setup the correct Facades.
Logging to the Debugbar
In order to log information to the Debugbar, you’ll need to add the facade for Debugbar; to do this, add 'Debugbar' => 'Barryvdh\Debugbar\Facade',
to your facades array in the app/config/app.php
file. Now you’ll be able to log reference material to the console that the Debugbar provides.
Debugbar::info($object);
Debugbar::error("Error!");
Debugbar::warning('Watch out..');
Debugbar::addMessage('Another message', 'mylabel');
More Info
There’s a bunch more that you can do with the Debugbar, but I’ll let their GitHub page cover that. Check it out for more information on the Laravel Debugbar!