Laravel Lumen - Eloquent Query Log

To get the query log in Laravel Lumen working you need to enable it:

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

You can add that code in to your controller, middleware, etc then use:

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

dd($lastQuery)

To print your query.

You can also use the following with eloquent:

$myModel = Users::where('active', true);

dd($myModel->getSql(), $myModel->getBindings());

You must run the getSql() and getBindings() before you call ->first() or ->get(), etc


Just call this after the query to keep it quick and simple:

echo $query->toSql();

Tags:

Laravel

Lumen