Sometimes it's useful for debugging purposes to preview the query that Laravel generates with Eloquent/Fluent.
(!) In Laravel 5 you should enable query logging by:
Then after placing your final statement:
DB::table('users')->where('name', '=', 'Aknavi')->get();
dd(DB::getQueryLog()); - it will return the SQL and the bindings of the last queries that were executed.
In Laravel 4
queryLogging is enabled by default, so you can just dump the query log:
In Laravel 3 you can run:
But you must enable the profiler, first (
Or you can use the profiler to get all queries executed for the current request and their execution time.
Aron Visuals provided this incredible picture!