Skip to content

Instantly share code, notes, and snippets.

@absent1706
Last active July 1, 2016 19:23
Show Gist options
  • Save absent1706/59dbd8dad69cd6c933393a7b67e5d728 to your computer and use it in GitHub Desktop.
Save absent1706/59dbd8dad69cd6c933393a7b67e5d728 to your computer and use it in GitHub Desktop.
<?php
// in app/Providers/AppServiceProvider
/*namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{*/
public function boot()
{
if (\App::environment('local')) {
\Event::listen('Illuminate\Database\Events\QueryExecuted', function ($query) {
$msg = "== SQL: ".$query->sql."\n";
$msg .= "== Params: ".join(', ', $query->bindings)."\n\n";
// if code is executed in CLI, echo message
if (\App::runningInConsole()) {
echo $msg."\n\n";
}
// if code executed by server, log message
else {
// \Log::debug($msg);
error_log($msg); // log into php builtin server
}
});
}
}
/*
public function register()
{
//
}
}/*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment