Skip to content

Instantly share code, notes, and snippets.

@gvsrepins
Last active December 20, 2024 19:00
Show Gist options
  • Save gvsrepins/f677e3f8d29a34028188442e70e60f98 to your computer and use it in GitHub Desktop.
Save gvsrepins/f677e3f8d29a34028188442e70e60f98 to your computer and use it in GitHub Desktop.
Log all executed queries in a Laravel application (check storage/logs/laravel.log file)
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*/
public function boot(): void
{
DB::listen(function($query) {
Log::info(
$query->sql,
[
'bindings' => $query->bindings,
'time' => $query->time
]
);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment