Menü schliessen
Created: May 27th 2025
Last updated: June 13th 2025
Categories: Common Web Development,  IT Development,  Laravel
Author: Tim Fürer

Laravel: Debug with PHP Debug Bar

Tags:  debugging,  guide,  Laravel,  PHP
Donation Section: Background
Monero Badge: QR-Code
Monero Badge: Logo Icon Donate with Monero Badge: Logo Text
82uymVXLkvVbB4c4JpTd1tYm1yj1cKPKR2wqmw3XF8YXKTmY7JrTriP4pVwp2EJYBnCFdXhLq4zfFA6ic7VAWCFX5wfQbCC

Debugging is important, but with PHP it can prove quite annoying. Even a simple task such as dumping some values can already present a significant challenge when echo and co. aren't viable (personally, I like to abuse a combination of output buffering, print_r(), and error_log() for dumping in those cases). When working with a complex framework, like Laravel, PHP's stock debug capabilities simply won't cut it. We need proper tooling. And that's exactly where PHP Debug Bar comes into play.


Installation

A version of PHP Debug Bar exists just for integration with Laravel. Install it as a development package using the following composer command:

composer require barryvdh/laravel-debugbar --dev

Once installed, publish its service provider using this artisan command:

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

Register the service provider in your app's "bootstrap/providers.php" file by adding the following class name to the pool of providers:

Barryvdh\Debugbar\ServiceProvider::class

Usage

To demonstrate, let's dump some values. You'll find dumped values in the "Messages" tab of the debug bar:

The main way to dump is by using the debug() helper function. It's useful for dumping all kinds of values with its interactive presentation and provides you with the relevant file name and line number (it's akin to JavaScript's console.log()):

use App\Models\User;

debug('testest');

debug([1, 2, 3]);

debug(User::factory()->make());

If you like, you can use the following methods in place of debug() for some additional semantic control:

use App\Models\User;
use Barryvdh\Debugbar\Facades\Debugbar;

Debugbar::info('testest');

Debugbar::error([1, 2, 3]);

Debugbar::warning(User::factory()->make());

Another method for dumping is the info() helper function. It always presents values as strings and provides you with a timestamp. While being viewable in the debug bar, the messages are also logged to your app's log file (usually located at "storage/logs/laravel.log") this way.

use App\Models\User;

info('testest');

info([1, 2, 3]);

info(User::factory()->make());