Skip to content

Instantly share code, notes, and snippets.

@joseadrian
Created August 24, 2015 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joseadrian/994802e339be42bc8907 to your computer and use it in GitHub Desktop.
Save joseadrian/994802e339be42bc8907 to your computer and use it in GitHub Desktop.
Log queries in console
<?php
Event::listen('illuminate.query', function($query, $binding, $time, $connections)
{
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
foreach ($backtrace as $trace) {
if(array_key_exists('file',$trace) && array_key_exists('line',$trace)){
if( strpos($trace['file'],base_path().'/app') !== false ){
PhpConsole\Handler::getInstance()->debug([
$trace['file'] . ':' . $trace['line'] => array(
'query' => $query,
'binding' => $binding
)
]);
break;
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment