laravel在xdebug調試的時候不能像tp同樣查看sql,比較麻煩,在網上查了一下資料,在此作個筆記: 一、使用socketLog來打印sql 到githuh下載socketLog文件,將php文件夾拷貝到項目根目錄; 二、在app/Providers/EventServiceProvider.php中的$listen內加入 'Illuminate\Database\Events\QueryExecuted' => [ 'App\Listeners\QueryListener', ], phpphp
php artisan event:generate生成監聽器laravel
添加內容 class QueryListener { /** * Create the event listener. * * @return void */ public function __construct() { // }git
/** * Handle the event. * * [@param](https://my.oschina.net/u/2303379) QueryExecuted $event * [@return](https://my.oschina.net/u/556800) void */ public function handle(QueryExecuted $event) { // if (env('APP_DEBUG', false)) { $slog = require_once __DIR__.'/../../php/slog.function.php'; $sql = str_replace("?", "'%s'", $event->sql); $log = vsprintf($sql, $event->bindings);
// Log::info($log); slog($log); } } } 三、其它就是socketLog的配置了sql