1

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.

user1995781
  • 19,085
  • 45
  • 135
  • 236
  • Maybe this helps: http://stackoverflow.com/questions/14536165/get-the-query-executed-in-laravel-3-4 – Grug Nov 20 '13 at 03:34

3 Answers3

1

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
Community
  • 1
  • 1
0

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.

Manuel Pedrera
  • 5,347
  • 2
  • 30
  • 47
0

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.

https://github.com/barryvdh/laravel-debugbar

SamV
  • 7,548
  • 4
  • 39
  • 50