//运行命令php artisan make:listener QueryListener --event=Illuminate\Database\Events\QueryExecuted
//创建的事件文件代码如下: sql); $log = vsprintf($sql, $event->bindings); \Log::channel('sqlog')->info($log); }}
在event服务提供者里配置下listen属性:
protected $listen = [ 'App\Events\Event' => [ 'App\Listeners\EventListener', ], //指定sql执行监听 'Illuminate\Database\Events\QueryExecuted' => [ 'App\Listeners\QueryListener' ] ];