Laravel Lumen - Query Journal Log

I am using Laravel Lumen to create an API.

I came to the point where I need to find out which SQL query is generated by Eloquent. I know how to do this in Laravel 4 and Laravel 5, but I tried the same code in Lumen and the request is empty?

$queries = DB::getQueryLog(); $last_query = end($queries); echo 'Query<pre>'; print_r($last_query); exit; 

The above code, when it works in Laravel, works fine - is the request empty in Lumen?

+5
source share
2 answers

To make the query log work in Laravel Lumen, you need to enable it:

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

You can add this code to your controller, middleware, etc., and then use:

 $queries = DB::getQueryLog(); $lastQuery = end($queries); dd($lastQuery) 

To print your request.

You can also use the following with eloquent:

 $myModel = Users::where('active', true); dd($myModel->getSql(), $myModel->getBindings()); $myModel->get(); 
+6
source

Just call it after the request to be quick and easy:

 echo $query->toSql(); 
+1
source

All Articles