|
@@ -3,7 +3,8 @@
|
|
|
namespace App\Providers;
|
|
|
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
-
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
+use Illuminate\Support\Facades\Log;
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
|
{
|
|
|
/**
|
|
@@ -23,6 +24,19 @@ class AppServiceProvider extends ServiceProvider
|
|
|
*/
|
|
|
public function boot()
|
|
|
{
|
|
|
- //
|
|
|
+ //把SQL输出到日志中
|
|
|
+ if ($this->app->environment('local')) { // 仅在本地环境启用
|
|
|
+ DB::listen(function ($query) {
|
|
|
+ // 格式化 SQL 语句
|
|
|
+ $sql = $query->sql;
|
|
|
+ foreach ($query->bindings as $binding) {
|
|
|
+ $sql = preg_replace('/\?/', "'" . addslashes($binding) . "'", $sql, 1);
|
|
|
+ }
|
|
|
+ // 输出到控制台
|
|
|
+ //dump($sql . ' [' . $query->time . 'ms]');
|
|
|
+ //输出到log
|
|
|
+ Log::info($sql . ' [' . $query->time . 'ms]');
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
}
|