Created
June 17, 2022 12:18
-
-
Save tfevens/3e307627332d76710afb6367b997ed01 to your computer and use it in GitHub Desktop.
Capture all queries in a log file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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