How to use Eloquent ORM getQueryLog () outside Laravel?

I tried to figure out a way to write SQL queries from Eloquent ORM, which I use in Zend Framework 1. I came across the getQueryLog () method, called as follows:

$queries = DB::getQueryLog(); 

I found Illuminate \ Database \ Connection to contain the getQueryLog () method, so I tried to do the following:

 use Illuminate\Database\Connection as DB; class IndexController { . . . public function indexAction() { // do stuff (eg fetch/update/create rows) $questions = Questions::all() . . $queries = DB::getQueryLog(); var_dump($queries); exit; . // render view } } 

However, I get the following notification and return NULL: Notice: Undefined property: IndexController::$queryLog in /var/www/qasystem/vendor/illuminate/database/Illuminate/Database/Connection.php on line 918 NULL

Can anyone suggest how I can use this outside of Laravel? I searched the Internet and see nothing that I need to do differently, although I suspect that most of the examples will be used in Laravel. Also, is Illuminate \ Database \ Connection the right class? Thanks

+5
source share
1 answer

Use toSql . It will return the final request command to you.

See How to get a query builder to display its raw SQL query as a string? for more information

+2
source

Source: https://habr.com/ru/post/1211316/


All Articles