Sometimes it's useful for debugging purposes to preview the query that Laravel generates with Eloquent/Fluent.

Laravel 5

(!) In Laravel 5 you should enable do



Then after placing your final statement:

DB::table('users')->where('name', '=', 'Aknavi')->get();  

just run:

dd(DB::getQueryLog()); - it will return the SQL and the bindings of the last queries that were executed.

Laravel 4

In Laravel 4 queryLogging is enabled by default, so you should just do:


Laravel 3

In Laravel 3 you can run


But you should have profiler enabled in application/config/database.php

Or you can use the profiler to get all queries executed for the current request and their execution time.