frostrain / laravel-console-debug
在控制台显示调试信息
0.2.0
2017-12-03 03:41 UTC
Requires
- barryvdh/laravel-debugbar: 2.*|3.*
This package is not auto-updated.
Last update: 2024-09-20 22:28:09 UTC
README
依赖
- laravel 5 (5.0 - 5.5)
- barryvdh/laravel-debugbar (laravel-debugbar 本身不会在控制台显示调试消息)
介绍
此包可以显示 laravel-debugbar 的调试消息和 SQL 查询 控制台。
例如,有一个 test
命令
# if you dosen't use -v flag, it will not display debug messages $ php artisan test hello! # with -v or more verbose flag, it will display debug messages $ 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
命令的示例(此示例需要 laravel 5.4+ 运行,你需要将这些代码放入 routes/console.php
中,对于 laravel 5.3 及以下版本,你可以使用 Command
类)
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' => [ // ... // Register laravel-debugbar's service first Barryvdh\Debugbar\ServiceProvider::class, Frostrain\Laravel\ConsoleDebug\ConsoleDebugServiceProvider::class, ]
然后你可以使用 -v
或更详细的标志来显示调试消息
php artisan test -v
配置(可选)
你可以发布配置文件
php artisan vendor:publish --provider="Frostrain\Laravel\ConsoleDebug\ConsoleDebugServiceProvider"
然后在自己的 config/console_debug.php
中设置配置。