Laravel Debugbar消息未显示

时间:2015-08-23 00:11:29

标签: php laravel-5

L5.0

我安装了DebugBar,它正在工作并显示在屏幕底部。但是我无法弄清楚如何将消息发送到控制台以显示在"消息"

我在我的控制器中尝试了以下内容......

use DebugBar\DebugBar;
....
DebugBar::addMessage('This is a message');

甚至

use DebugBar\DebugBar;
....
DebugBar::info('this is info');

但我收到以下错误。

Call to undefined method DebugBar\DebugBar::info()

我的app.php有以下内容。

'providers' => [
.....
'Barryvdh\Debugbar\ServiceProvider',
....


'aliases' => [ 
....
'DebugBar'  => 'Barryvdh\Debugbar\Facade',

我还是一个Laravel新手,所以不知道接下来要去哪里检查。我已经检查了http://phpdebugbar.com/docs/https://github.com/barryvdh/laravel-debugbar上的文档,但我认为我只是遗漏了一些东西。

4 个答案:

答案 0 :(得分:4)

我认为问题是,您以错误的方式使用provider-array。它应该是:

'providers' => [
    ...
    Barryvdh\Debugbar\ServiceProvider::class,
]

config/app.php中。另外,请使用以下内容代替上面写的字符串:

'aliases' => [
    ...
    'DebugBar' => Barryvdh\Debugbar\Facade::class,
]

我在一个干净的Laravel-5安装上尝试了你的配置,它没有用。这可能是绝对的类路径。使用上面列出的配置,它可以很好地工作。

答案 1 :(得分:3)

如果你想在这个过程中显示DebugBar:

'providers' => [
    ...
    Barryvdh\Debugbar\ServiceProvider::class,
]

然后

'aliases' => [
    ...
    'DebugBar' => Barryvdh\Debugbar\Facade::class,
]

然后在你的控制器中写

app('debugbar')->error('Watch out..');

现在刷新浏览器,然后看到消息享受

答案 2 :(得分:0)

另外请确保Barryvdh\Debugbar\ServiceProvider::class是提供者列表中的第一个。

答案 3 :(得分:0)

对我来说,我的IDE所建议的自动注入DebugBar\DebugBar不能自动运行,但是会出现此错误。将其更改为Barryvdh\Debugbar\Facade as DebugBar可解决此问题。似乎在默认的Laravel配置中安装了一个完全不同的名为“ DebugBar”的软件包。

因此,如果在文件开头,您将看到:

use DebugBar\DebugBar;

将其更改为:

use Barryvdh\Debugbar\Facade as DebugBar;

此外,如果注册为立面,则始终可以使用\DebugBar::addMessage('This is a message');等,而无需先注入,就像您告诉Laravel如何解析类一样。这样,您无需先use