-
app/Providers/QueryLogServiceProvider.php
Open in GitHubuse Illuminate\Support\ServiceProvider; class QueryLogServiceProvider extends ServiceProvider { public function boot() { if (config('app.log_queries') === true) { $this->logQueries(); } } protected function logQueries(): void { \DB::listen(function ($sql) { $query = $sql->sql; foreach ($sql->bindings as $key => $binding) { if ($key === array_key_first($sql->bindings)) { $query = "{$query} ["; } $query = "{$query}{$binding}, "; if ($key === array_key_last($sql->bindings)) { $query = rtrim($query, ', ') . ']'; } } $query = "{$query} ({$sql->time} ms)"; \Log::debug($query); }); } }
-
config/app.php
Open in GitHubreturn [ // 'log_queries' => env('LOG_QUERIES', false), // 'providers' => [ // App\Providers\QueryLogServiceProvider::class, // ], // ];