Laravel-数据库监听
<?php
namespace App\Providers;
class AppServiceProvider extends ServiceProvider
{
public function boot(){
DB::listen(function($query){
//剔除命令行sql
if(app()->runningInConsole()) return;
$request = request();
//防止重复录入形成死循环 sql_log有关的表不显示
if(strpos($query->sql,'sql_log' !=false)) return;
$sqlLog = [
'sql' => vsprintf(str_replace("?", "'%s'", $query->sql), $query->bindings),
'time' => $query->time,
'url' => $query->url,
'fingerprint' => $request->fingerprint()
];
});
}
}
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!