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 doDB::enableQueryLog();
first.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 4queryLogging is enabled by default, so you should just do:dd(DB::getQueryLog());
Laravel 3
In Laravel 3 you can runDB::last_query();
But you should have profiler enabled in application/config/database.phpOr you can use the profiler to get all queries executed for the current request and their execution time.
Comments
Post a Comment