Created
February 6, 2016 19:22
-
-
Save elomatreb/a28d26a329347af030ae to your computer and use it in GitHub Desktop.
Laravel Service Provider that logs all SQL queries (with bindings).
This file contains hidden or 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
<?php | |
namespace App\Providers; | |
use Illuminate\Support\ServiceProvider; | |
use DB; | |
use Log; | |
/** | |
* Service provider that logs all SQL queries (with bindings). | |
* | |
* To use: Place this file in the app/Providers directory and put "App\Providers\LogSqlProvider::class" | |
* in the "providers" array in your app config (config/app.php). | |
*/ | |
class LogSqlProvider extends ServiceProvider | |
{ | |
/** | |
* Bootstrap the application services. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
DB::listen(function ($query) { | |
Log::debug("[sql] [query] " . $query->sql); | |
Log::debug("[sql] [bindings] " . print_r($query->bindings, true)); | |
}); | |
} | |
/** | |
* Register the application services. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
// | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How can I save to db the query without causing infinite loops?