Laravel Debugbar
repository·master·Indexed 12 days ago
https://github.com/fruitcake/laravel-debugbarA package that integrates the PHP Debug Bar with Laravel, providing specialized collectors for Laravel-specific data such as queries, routes, views, and events. It includes a facade for logging and timing, support for Laravel Octane 4.x, and various data collectors for monitoring memory usage, cache hits, Eloquent models, and more.
What's inside Laravel Debugbar
- Laravel Debugbar is a package that integrates PHP Debug Bar into the Laravel framework. It provides a visual interface to debug database queries and profile various aspects of your application's performance and lifecycle through various collectors.
How Debugbar activation works
masterBy default, the Debugbar is automatically enabled only when:
APP_DEBUGis set totrue.- The environment is not
productionortesting.
Manual Control:
- You can disable it via the
debugbar.enabledconfig key or theDEBUGBAR_ENABLEDenvironment variable. - If you need to enable it in a production environment (not recommended), you must set
debugbar.force_allow_enabletotrueor use theDEBUGBAR_FORCE_ALLOW_ENABLE=trueenvironment variable. This allows the ServiceProvider to bootstrap so you can callDebugbar::enable()at runtime.
Use on-demand query EXPLAIN
masterBy enabling
options.db.explain.enabledin your configuration, you can run on-demandEXPLAINqueries for anySELECTstatement directly within the Debugbar interface. This helps in analyzing query performance and provides a link tomysqlexplain.comfor visual explanation.'options' => [ 'db' => [ 'explain' => [ 'enabled' => true, ], ], ],Debug messages with debug() and Trace
masterThe Messages Collector gathers data fromdebug()calls and log entries. You can pass complex objects or multiple parameters todebug(). When usingdebug(), the collector shows the source of the call, allowing you to open the specific line in your IDE.Migrate from 3.x to 4.x
masterWhen upgrading from version 3.x to 4.x, note the following breaking changes:
- Dependencies: The
php-debugbardependency is now 3.x, which removesjQueryandfont-awesome. If you use custom collectors, ensure they do not rely on these assets. - Namespace: The namespace has changed from
Barryvdh\DebugbartoFruitcake\LaravelDebugbar. You only need to update this if you are manually registering the Service Provider or the Facade. - Package Name: The composer package name is now
fruitcake/laravel-debugbar. - Removed Features:
SocketStorageis removed.- Lumen support is removed.
FileCollectoris removed.- Global helper methods
start_measure(),add_measure(),stop_measure(), andmeasure()are removed. Usedebugbar()->startMeasure()and related methods instead.
- Dependencies: The
Extend Laravel Debugbar in version 4.x
masterIf you are developing a package that extends Laravel Debugbar, you must implement the following changes for version 4.x:
- Response Handling: The
modifyResponsemethod has been renamed tohandleResponse. It is now implemented via a listener rather than middleware. - HTTP Driver: The
HttpDriveris now session-less and utilizes cookies. - Laravel Octane: Because Octane maintains the
LaravelDebugbarstate, collectors must be reset. You can now removeLaravelDebugbarfrom your application'sflushconfiguration.
- Response Handling: The
Install without Package Auto-Discovery
masterIf your Laravel installation does not use auto-discovery, you must manually register the ServiceProvider:
- Laravel 11 or newer: Add
Fruitcake\LaravelDebugbar\ServiceProvider::classtobootstrap/providers.php. - Laravel 10 or older: Add
Fruitcake\LaravelDebugbar\ServiceProvider::classto theprovidersarray inconfig/app.php.
To use the
Debugbarfacade for logging messages, register an alias in theregistermethod of yourapp/Providers/AppServiceProvider.php:public function register(): void { $loader = \Illuminate\Foundation\AliasLoader::getInstance(); $loader->alias('Debugbar', \Fruitcake\LaravelDebugbar\Facades\Debugbar::class); }- Laravel 11 or newer: Add
Laravel Debugbar with Octane
masterLaravel Debugbar 4.x supports Laravel Octane out of the box without additional configuration.
Migration Note: If you are upgrading from version 3.x, you must remove the
'flush'configuration for Debugbar from yourconfig/octane.phpfile.Publish Debugbar configuration
masterTo customize the Debugbar behavior, publish the package configuration file to your local
config/directory using the Artisan command.php artisan vendor:publish --provider='Fruitcake\LaravelDebugbar\ServiceProvider'Enable or disable Laravel Debugbar
masterBy default, Debugbar is enabled when
APP_DEBUGis set totruein your environment.You can explicitly control its state using the following methods:
- Environment Variable: Set
DEBUGBAR_ENABLEDin your.envfile. - Configuration File: Set the
enabledkey inconfig/debugbar.php.
If you use a catch-all or fallback route, ensure the Debugbar ServiceProvider is loaded before your own application ServiceProviders.
// config/debugbar.php 'enabled' => env('DEBUGBAR_ENABLED', null), // You can also define URIs to ignore 'except' => [ 'telescope*', 'horizon*', ],- Environment Variable: Set
Use Laravel Debugbar with Octane
masterLaravel Debugbar 4.x supports Laravel Octane out of the box without additional configuration.
Note for Upgraders: If you are upgrading from version 3.x, you must remove the
'flush'configuration for Debugbar from yourconfig/octane.phpfile.Use Debugbar in Console Commands
masterTo log data to the Debugbar while running Console Commands, you must manually enable it. You can then view the captured data by browsing the Debugbar requests in the web UI.
debugbar()->enable();