Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
LogSql::useFiles(storage_path().'/logs/laravel_sql.log');
Event::listen('illuminate.query', function($query, $bindings, $time, $name)
{
$data = compact('bindings', 'time', 'name');
foreach ($bindings as $i => $binding)
{
if($binding instanceof \DateTime)
{
$bindings[$i] = $binding->format('\'Y-m-d H:i:s\'');
}elseif(is_string($binding)){
$bindings[$i] = "'$binding'";
}
}
$query = str_replace(array('%', '?'), array('%%', '%s'), $query);
$query = vsprintf($query, $bindings);
LogSql::info($query, $data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.