Laravel 5 Print Last Query
Laravel 5 Print Last Query : As developer for debugging the queries we often need to print the queries executed in our program which helps us to work more efficiently. In laravel you need to enable query log DB::enableQueryLog();before the query and then you can print queries as $queries = DB::getQueryLog();
Laravel 5 Print Last Query Example And Syntax
Here is simple example of printing queries in laravel –
Laravel 5 Print Last Query :
DB::enableQueryLog();// enable query first // Your queries goes here // ... // Now print Queries executed.... $queries = DB::getQueryLog(); foreach($queries as $k=>$query) { Log::debug(" $k Query - " . json_encode($query)); } |
Which will print all queries executed.
Note : DB::enableQueryLog(); should be enabled before you log.
Advertisements