Last active
November 16, 2018 10:09
-
-
Save vocolboy/d6cd7082f2fcbdb7c10893de1df2a088 to your computer and use it in GitHub Desktop.
Laravel5.7 Log Query Executed
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
#Put It In AppServiceProvider.php | |
<?php | |
use Illuminate\Database\Events\QueryExecuted; | |
use DB; | |
use Log; | |
... | |
public function boot() | |
{ | |
... | |
DB::listen(function (QueryExecuted $event) { | |
tap(collect($event->bindings)->map(function ($params) { | |
return (is_numeric($params)) ? $params : "'$params'"; | |
})->toArray(), function (array $bindings) use ($event) { | |
Log::info('QueryExecuted', [ | |
'sql' => vsprintf(str_replace('?', '%s', $event->sql), $bindings), | |
'time' => $event->time, | |
]); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment