In many cases we need to debug or print large queries in Laravel to verify exact scenario of written queries. And we know laravel have built-in functions for debug or print query.


There are many option to debug or print executed query in laravel 5:

First option is to listen for query events on the DB object. To set this, you can add below script to your portal.config file or above the written query.
First option script:

Now when you load or refresh the page in the browser you will get the below output as in the query debugging section or console section or in page itself:

Output for First option:

Now in Second option, DB::listen is more advanced, and it accepts two more parameters to give access to the passed values or array parameters in bindings and the time the query took to execute or run:

Second option script:

Running the above script, you will be able to display the following below results:

Output of second script:

As you can see above by both results, Both script gives complete query, the bindings, and the time the query took to run or execute.

From the above query and array values ,we can easily match and manually run the query in any MYSql client to verify the executed query.Thanks.Please write to us if you have any query.

You can also see:

<<<<< Import and export database in MySql through command line in linux

<<<<< PHP tutorial for beginner Day 4 –  Echo and Print operation in PHP

<<<<< PHP tutorial for beginner Day 3 –  variable scope and type of variable

<<<<< PHP tutorial for beginner Day 2 – Syntax overview and tag

<<<<< PHP tutorial for beginner Day 1 – Introduction and Installation.