Laravel 5 Eloquent: How to get raw sql that is being executed? (with binded data)

前端 未结 5 1625
栀梦
栀梦 2021-02-06 01:13

Im trying to figure out how to get the raw sql query being executed including the binded data in it. Here is what ive got:

\\DB::connection()->enableQueryLog(         


        
5条回答
  •  [愿得一人]
    2021-02-06 01:27

    Add this in your routes Folder :

    \Event::listen('Illuminate\Database\Events\QueryExecuted', function ($query) {
        Log::info( json_encode($query->sql) );
        Log::info( json_encode($query->bindings) );
        Log::info( json_encode($query->time)   );
    });
    

    Log::info() ==> will log the SQL query in your storage/logs/laravel.log file

    var_dump() ==> will display in the API call output

提交回复
热议问题