Skip to content

Instantly share code, notes, and snippets.

@tfevens
Created June 17, 2022 12:18
Show Gist options
  • Save tfevens/3e307627332d76710afb6367b997ed01 to your computer and use it in GitHub Desktop.
Save tfevens/3e307627332d76710afb6367b997ed01 to your computer and use it in GitHub Desktop.
Capture all queries in a log file.
// Add this in the register() method.
// Credit to @trovster -> https://twitter.com/trovster/status/1537082202709803008
if (! $this->app->isProduction()) {
DB::listen(function ($query): void {
$date = Carbon::today()->toDateString();
$filepath = storage_path("logs/queries-{$date}.log");
File::append(
$filepath,
$query->sql . '[' . implode(', ', $query->bindings) . ']' . PHP_EOL
);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment