Showing posts with label Laravel. Show all posts
Showing posts with label Laravel. Show all posts

Monday, 29 September 2014

Laravel : Display all SQL executed in Eloquent

Put this in your routes.php file and you will see the SQL that Eloquent is executing when you go to pages that have any sort of access to Eloquent models. This helps a lot when debugging SQL in Laravel.





// Display all SQL executed in Eloquent
Event::listen('illuminate.query', function($query)
{
    var_dump($query);
});


How to print SQL Query in Lravel 4.2

To output to the screen the last queries ran you can use this


dd(DB::getQueryLog());


Use the toSql() method on a QueryBuilder instance.

DB::table('users')->toSql() would return: 

select * from `users`