When working on Laravel, we do query like this:
$user = DB::table('users')->where('name', 'John')->first();
How can I view the generated sql query? This is something very important for debugging during the development.
Thank you.
When working on Laravel, we do query like this:
$user = DB::table('users')->where('name', 'John')->first();
How can I view the generated sql query? This is something very important for debugging during the development.
Thank you.
According to this answer, you should be able to use this to get the last executed query :
$queries = DB::getQueryLog(); // gets a log of all executed queries
$last_query = end($queries); // gets the last one
You can also add this snippet:
Event::listen('illuminate.query', function($sql)
{
var_dump($sql);
});
It will output all queries being executed in your request.
Not a direct answer as other people have answered this but take a look at this composer package, it is very helpful and displays all of your queries and more.