Laravel Debugbar 翻译

Laravel Debugbar

Packagist License
Latest Stable Version
Total Downloads

注意在v3版本中: Debugbar将会在引入后会自动被启用,但是仍然需要将APP_DEBUG设置为true!

Laravel<5.5的版本请始用2.4 版本!

这是一个将 PHP Debug Bar 整合进Laravel5的扩展包.
更多配置选项请查阅 配置文档


注意: DebugBar仅供开发环境下始用. 它将导致应用程序运行缓慢 (因为它需要手机数据). 所以在运行缓慢的时候,尝试禁用一些收集器.

- ueryCollector:显示所有查询,包含绑定和时间。
- outeCollector:显示当前路由信息。
- iewCollector:显示当前加载的视图。(可选:显示共享数据)
- ventsCollector:显示所有事件。
- aravelCollector:显示Laravel版本和环境。(默认关闭)
- ymfonyRequestCollector:替换 RequestCollector,显示关于请求/响应的更多信息。
- ogsCollector:显示来自日志文件的最新日志条目。(默认关闭)
- ilesCollector:显示 PHP include/require 的文件。(默认关闭)
- ConfigCollector:显示配置文件配置值。(默认关闭)
- CacheCollector: 显示缓存事件。(默认关闭)

- LogCollector: 显示所有日志信息
- 为邮件提供的 SwiftMailCollector 和 SwiftLogCollectorl

- PhpInfoCollector
- MessageCollector
- TimeDataCollector(包含启动及应用时间)
- MemoryCollector
- ExceptionsCollector



使用Composerrequire --dev 命令导入这个包。这将仅在开发模式下引入这个包。

composer require barryvdh/laravel-debugbar --dev

在Laravel 5.5 中将始用 Package Auto-Discovery自动导入这个包, 所以你不需要手动添加 ServiceProvider.

Debugbar 将会在 APP_DEBUGtrue 的时候启用.

If you use a catch-all/fallback route, make sure you load the Debugbar ServiceProvider before your own App ServiceProviders.

Laravel 5.5+:

如果你没有始用 auto-discovery ,需要添加 ServiceProviderconfig/app.phpproviders 数组中:


如果你想要始用Facade来记录信息,添加这个到 app.phpfacedes:

'Debugbar' => Barryvdh\Debugbar\Facade::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"


For Lumen, register a different Provider in bootstrap/app.php:

if (env('APP_DEBUG')) {

To change the configuration, copy the file to your config folder and enable it:



You can now add messages using the Facade (when added), using the PSR-3 levels (debug, info, notice, warning, error, critical, alert, emergency):

Debugbar::warning('Watch out…');
Debugbar::addMessage('Another message', 'mylabel');

And start/stop timing:

Debugbar::startMeasure('render','Time for rendering');
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) {

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);

start_measure('render','Time for rendering');
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

$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.


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.

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)


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 %}