Skip to content

Latest commit

 

History

History
executable file
·
86 lines (74 loc) · 2.62 KB

README_cn.org

File metadata and controls

executable file
·
86 lines (74 loc) · 2.62 KB

Laravel Console Debug

https://api.travis-ci.org/frostrain/laravel-console-debug.svg?branch=master

依赖

介绍

这个包可以在 console 中显示 laravel-debugbar 收集到的 调试信息执行的sql.

比如这里有一个 test 命令

# 不带有 -v 参数时, 不显示 调试信息
$ php artisan test
hello!

# 带有 -v 或以上的参数才会显示 调试信息
$ php artisan test -v
hello!

+-------+---------------------+
| level | debug message       |
+-------+---------------------+
| info  | 中文消息            |
+-------+---------------------+
| error | some error msg...   |
+-------+---------------------+
| debug | {#753               |
|       |   +"foo": "bar"     |
|       |   +"arr": array:2 [ |
|       |     0 => "foo"      |
|       |     1 => "bar"      |
|       |   ]                 |
|       | }                   |
+-------+---------------------+

+-------------------------------+----------+
| sql                           | duration |
+-------------------------------+----------+
| select * from `users` limit 1 | 9.77ms   |
+-------------------------------+----------+

test 命令的例子, 需要写在 routes/console.php 中 (注意, laravel 5.4 和以上才能这样写)

Artisan::command('test', function(){
    $this->line('hello!');

    $debugbar = app('debugbar');
    $debugbar->info('中文消息');
    $obj = new StdClass();
    $debugbar->error('some error msg...');
    $obj->foo = 'bar';
    $obj->arr = ['foo', 'bar'];
    debug($obj);

    \App\User::first();
});

安装和使用

通过 composer 安装

composer require --dev frostrain/laravel-console-debug

然后在 config/app.php 中添加服务

'providers' => [
    // ...

    // 需要先注册 laravel-debugbar 的服务
    Barryvdh\Debugbar\ServiceProvider::class,
    Frostrain\Laravel\ConsoleDebug\ConsoleDebugServiceProvider::class,
]

然后就可以使用 -v 或以上的参数(-vv, -vvv)来显示调试信息

php artisan test -v

配置 (可选操作)

你可以设置自己的配置, 通过下面的命令将配置文件复制到 config/console_debug.php, 然后修改其中的配置即可

php artisan vendor:publish --provider="Frostrain\Laravel\ConsoleDebug\ConsoleDebugServiceProvider"