barryvdh / laravel-debugbar
PHP Debugbar integration for Laravel
Fund package maintenance!
barryvdh
fruitcake.nl
Installs: 88 032 140
Dependents: 682
Suggesters: 17
Security: 0
Stars: 17 407
Watchers: 280
Forks: 1 561
Open Issues: 75
Requires
- php: ^8.0
- illuminate/routing: ^9|^10|^11
- illuminate/session: ^9|^10|^11
- illuminate/support: ^9|^10|^11
- maximebf/debugbar: ~1.23.0
- symfony/finder: ^6|^7
Requires (Dev)
- mockery/mockery: ^1.3.3
- orchestra/testbench-dusk: ^5|^6|^7|^8|^9
- phpunit/phpunit: ^9.6|^10.5
- squizlabs/php_codesniffer: ^3.5
- dev-master / 3.14.x-dev
- v3.14.7
- v3.14.6
- v3.14.5
- v3.14.4
- v3.14.3
- v3.14.2
- v3.14.1
- v3.14.0
- v3.13.5
- v3.13.4
- v3.13.3
- v3.13.2
- v3.13.1
- v3.13.0
- v3.12.4
- v3.12.3
- v3.12.2
- v3.12.1
- v3.12.0
- v3.11.1
- v3.11.0
- v3.10.6
- v3.10.5
- v3.10.4
- v3.10.3
- v3.10.2
- v3.10.1
- v3.10.0
- 3.9.x-dev
- v3.9.3
- v3.9.2
- v3.9.1
- v3.9.0
- v3.8.2
- v3.8.1
- v3.8.0
- v3.7.0
- v3.6.8
- v3.6.7
- v3.6.6
- v3.6.5
- v3.6.4
- v3.6.3
- v3.6.2
- v3.6.1
- v3.6.0
- v3.5.7
- V3.5.6
- v3.5.5
- v3.5.4
- v3.5.3
- v3.5.2
- v3.5.1
- v3.5.0
- 3.4.x-dev
- v3.4.2
- v3.4.1
- v3.4.0
- v3.3.3
- v3.3.2
- v3.3.1
- v3.3.0
- v3.2.9
- v3.2.8
- v3.2.7
- v3.2.6
- v3.2.5
- v3.2.4
- v3.2.3
- v3.2.2
- v3.2.1
- v3.2.0
- v3.1.5
- v3.1.4
- v3.1.3
- v3.1.2
- v3.1.1
- v3.1.0
- v3.0.1
- v3.0.0
- 2.4.x-dev
- v2.4.3
- v2.4.2
- v2.4.1
- v2.4.0
- v2.3.2
- v2.3.1
- v2.3.0
- V2.2.3
- v2.2.2
- v2.2.1
- v2.2.0
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- 1.8.x-dev
- v1.8.9
- v1.8.8
- v1.8.7
- v1.8.6
- v1.8.5
- v1.8.4
- v1.8.3
- v1.8.2
- v1.8.1
- v1.8.0
- v1.7.7
- v1.7.6
- v1.7.5
- v1.7.4
- v1.7.3
- v1.7.2
- v1.7.1
- v1.7.0
- v1.6.8
- v1.6.7
- v1.6.6
- v1.6.5
- v1.6.4
- v1.6.3
- v1.6.2
- v1.6.1
- v1.6.0
- v1.5.5
- v1.5.4
- v1.5.3
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4
- v1.3.1
- v1.3
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0
- v0.3.2
- v0.3.1
- v0.3
- v0.2
- v0.1.0
- dev-test-limits
- dev-barryvdh-patch-2
- dev-check-content-string
- dev-feat-exclude-queries
- dev-feat-hide-empty-tabs
- dev-feat-copy-icon
- dev-feat-fix-redirect-session
- dev-fix-artifacts
- dev-nckrtl-ui-refinements
- dev-feat-limit-queries
- dev-barryvdh-patch-1
- dev-barryvdh-php8.1
- dev-feat-cspnonce
- dev-feat-injecthead
- dev-feat-multiauth
- dev-telescope-link
- dev-feat-csp
- dev-revert-339-dha0stw-patch-disableVendors
- dev-reset
- dev-revert-353-1.8
- dev-revert-463-master
- dev-revert-350-fix_query_logging_is_off
This package is auto-updated.
Last update: 2024-11-14 10:50:45 UTC
README
This is a package to integrate PHP Debug Bar with Laravel. It includes a ServiceProvider to register the debugbar and attach it to the output. You can publish assets and configure it through Laravel. It bootstraps some Collectors to work with Laravel and implements a couple custom DataCollectors, specific for Laravel. It is configured to display Redirects and (jQuery) Ajax Requests. (Shown in a dropdown) Read the documentation for more configuration options.
Caution
Use the DebugBar only in development. Do not use Debugbar on publicly accessible websites, as it will leak information from stored requests (by design).
Warning
It can also slow the application down (because it has to gather and render data). So when experiencing slowness, try disabling some of the collectors.
This package includes some custom collectors:
- QueryCollector: Show all queries, including binding + timing
- RouteCollector: Show information about the current Route.
- ViewCollector: Show the currently loaded views. (Optionally: display the shared data)
- EventsCollector: Show all events
- LaravelCollector: Show the Laravel version and Environment. (disabled by default)
- SymfonyRequestCollector: replaces the RequestCollector with more information about the request/response
- LogsCollector: Show the latest log entries from the storage logs. (disabled by default)
- FilesCollector: Show the files that are included/required by PHP. (disabled by default)
- ConfigCollector: Display the values from the config files. (disabled by default)
- CacheCollector: Display all cache events. (disabled by default)
Bootstraps the following collectors for Laravel:
- LogCollector: Show all Log messages
- SymfonyMailCollector for Mail
And the default collectors:
- PhpInfoCollector
- MessagesCollector
- TimeDataCollector (With Booting and Application timing)
- MemoryCollector
- ExceptionsCollector
It also provides a facade interface (Debugbar
) for easy logging Messages, Exceptions and Time
Installation
Require this package with composer. It is recommended to only require the package for development.
composer require barryvdh/laravel-debugbar --dev
Laravel uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.
The Debugbar will be enabled when APP_DEBUG
is true
.
If you use a catch-all/fallback route, make sure you load the Debugbar ServiceProvider before your own App ServiceProviders.
Laravel without auto-discovery:
If you don't use auto-discovery, add the ServiceProvider to the providers list. For Laravel 11 or newer, add the ServiceProvider in bootstrap/providers.php. For Laravel 10 or older, add the ServiceProvider in config/app.php.
Barryvdh\Debugbar\ServiceProvider::class,
If you want to use the facade to log messages, add this within the register
method of app/Providers/AppServiceProvider.php
class:
public function register(): void { $loader = \Illuminate\Foundation\AliasLoader::getInstance(); $loader->alias('Debugbar', \Barryvdh\Debugbar\Facades\Debugbar::class); }
The profiler is enabled by default, if you have APP_DEBUG=true. You can override that in the config (debugbar.enabled
) or by setting DEBUGBAR_ENABLED
in your .env
. See more options in config/debugbar.php
You can also set in your config if you want to include/exclude the vendor files also (FontAwesome, Highlight.js and jQuery). If you already use them in your site, set it to false.
You can also only display the js or css vendors, by setting it to 'js' or 'css'. (Highlight.js requires both css + js, so set to true
for syntax highlighting)
Copy the package config to your local config with the publish command:
php artisan vendor:publish --provider="Barryvdh\Debugbar\ServiceProvider"
Laravel with Octane:
Make sure to add LaravelDebugbar to your flush list in config/octane.php
.
'flush' => [ \Barryvdh\Debugbar\LaravelDebugbar::class, ],
Lumen:
For Lumen, register a different Provider in bootstrap/app.php
:
if (env('APP_DEBUG')) { $app->register(Barryvdh\Debugbar\LumenServiceProvider::class); }
To change the configuration, copy the file to your config folder and enable it:
$app->configure('debugbar');
Usage
You can now add messages using the Facade (when added), 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');
And start/stop timing:
Debugbar::startMeasure('render','Time for rendering'); Debugbar::stopMeasure('render'); Debugbar::addMeasure('now', LARAVEL_START, microtime(true)); Debugbar::measure('My long operation', function() { // Do something… });
Or log exceptions:
try { throw new Exception('foobar'); } catch (Exception $e) { Debugbar::addThrowable($e); }
There are also helper functions available for the most common calls:
// All arguments will be dumped as a debug message debug($var1, $someString, $intValue, $object); // `$collection->debug()` will return the collection and dump it as a debug message. Like `$collection->dump()` collect([$var1, $someString])->debug(); start_measure('render','Time for rendering'); stop_measure('render'); add_measure('now', LARAVEL_START, microtime(true)); measure('My long operation', function() { // Do something… });
If you want you can add your own DataCollectors, through the Container or the Facade:
Debugbar::addCollector(new DebugBar\DataCollector\MessagesCollector('my_messages')); //Or via the App container: $debugbar = App::make('debugbar'); $debugbar->addCollector(new DebugBar\DataCollector\MessagesCollector('my_messages'));
By default, the Debugbar is injected just before </body>
. If you want to inject the Debugbar yourself,
set the config option 'inject' to false and use the renderer yourself and follow http://phpdebugbar.com/docs/rendering.html
$renderer = Debugbar::getJavascriptRenderer();
Note: Not using the auto-inject, will disable the Request information, because that is added After the response. You can add the default_request datacollector in the config as alternative.
Enabling/Disabling on run time
You can enable or disable the debugbar during run time.
\Debugbar::enable(); \Debugbar::disable();
NB. Once enabled, the collectors are added (and could produce extra overhead), so if you want to use the debugbar in production, disable in the config and only enable when needed.
Storage
Debugbar remembers previous requests, which you can view using the Browse button on the right. This will only work if you enable debugbar.storage.open
in the config.
Make sure you only do this on local development, because otherwise other people will be able to view previous requests.
In general, Debugbar should only be used locally or at least restricted by IP.
It's possible to pass a callback, which will receive the Request object, so you can determine access to the OpenHandler storage.
Twig Integration
Laravel Debugbar comes with two Twig Extensions. These are tested with rcrowe/TwigBridge 0.6.x
Add the following extensions to your TwigBridge config/extensions.php (or register the extensions manually)
'Barryvdh\Debugbar\Twig\Extension\Debug', 'Barryvdh\Debugbar\Twig\Extension\Dump', 'Barryvdh\Debugbar\Twig\Extension\Stopwatch',
The Dump extension will replace the dump function to output variables using the DataFormatter. The Debug extension adds a debug()
function which passes variables to the Message Collector,
instead of showing it directly in the template. It dumps the arguments, or when empty; all context variables.
{{ debug() }} {{ debug(user, categories) }}
The Stopwatch extension adds a stopwatch tag similar to the one in Symfony/Silex Twigbridge.
{% stopwatch "foo" %} …some things that gets timed {% endstopwatch %}