How can I retrieve the raw executed SQL query in Laravel 3/4 using Laravel Query Builder or Eloquent ORM?
For example, something like this:
DB::table('users')->where_status(1)->get();
Or:
(posts (id, user_id, ...))
User::find(1)->posts->get();
Otherwise, at the very least how can I save all queries executed to laravel.log?
The Loic Sharma SQL profiler does support Laravel 4, I just installed it. The instructions are listed here. The steps are the following:
"loic-sharma/profiler": "1.1.*"
in the require section in composer.jsonphp composer.phar self-update
in the console.php composer.phar update loic-sharma/profiler
in the console as well `'Profiler\ProfilerServiceProvider',
in the provider array in app.php'Profiler' => 'Profiler\Facades\Profiler',
in the aliasses array in app.php as wellphp artisan config:publish loic-sharma/profiler
in the consoleYou can also listen for query events using this:
See the information from the docs here under Listening For Query Events
To get the last executed query in laravel,We will use
DB::getQueryLog()
function of laravel it return all executed queries. To get last query we will useend()
function which return last executed query.I have taken reference from http://www.tutsway.com/how-to-get-the-last-executed-query-in-laravel.php.
put it in global.php it will log your sql query.
There is very easy way to do it, from your laravel query just rename any column name, it will show you an error with your query.. :)
Laravel 3
Another way to do this is:
For all Queries result:
For last Result: