Laravel 调试栏消息未显示

问题描述 投票:0回答: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 上的文档,但我想我只是错过了一些东西。

php laravel-5
5个回答
6
投票

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

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

然后

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

然后在你的控制器中写入

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

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


5
投票

我认为问题在于,您以错误的方式使用提供者数组。应该是:

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

在你的

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

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

我在干净的 Laravel-5 安装上尝试了你的配置,但它不起作用。这可能是由绝对类路径带来的。使用上面列出的配置,效果非常好。


2
投票

对我来说,按照我的 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
它。


0
投票

还要确保

Barryvdh\Debugbar\ServiceProvider::class
位于提供商列表中的第一位。


0
投票

内部

.env

DEBUGBAR_ENABLED=true
© www.soinside.com 2019 - 2024. All rights reserved.