12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- namespace App\Providers;
- use Illuminate\Support\ServiceProvider;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Log;
- class AppServiceProvider extends ServiceProvider
- {
- /**
- * Register any application services.
- *
- * @return void
- */
- public function register()
- {
- //
- }
- /**
- * Bootstrap any application services.
- *
- * @return void
- */
- public function boot()
- {
- // FIXME LILIN 开发环境打印SQL
- if (getenv('APP_ENV') == 'local_lilin'){
- DB::listen(function ($query) {
- $tmp = str_replace('?', '"' . '%s' . '"', $query->sql);
- $qBindings = [];
- foreach ($query->bindings as $key => $value) {
- if (is_numeric($key)) {
- $qBindings[] = $value;
- } else {
- $tmp = str_replace(':' . $key, '"' . $value . '"', $tmp);
- }
- }
- $tmp = vsprintf($tmp, $qBindings);
- $tmp = str_replace("\\", "", $tmp);
- Log::info(' execution time: ' . $query->time . 'ms; ' . $tmp);
- });
- }
- }
- }
|