Debugging Laravel Queries (toSql())

Debugging Laravel Queries (toSql())

Debugging laravel queries using the toSql() method

Laravel provides us a very simple and efficient way of running SQL database using the query builder and ORM system called Eloquent.

This system makes running queries extremely simple and allows us to running get, insert, create and update records with little efforts.

However their are days you would like to see the actual SQL being generated.

How to go about it

The easiest way to see your query is by using the toSQL method provided by laravel itself. You just have to replace the get() method with toSql() method. Then we can print out the result by using the dd() method known as die and dump provided by laravel helper.

carbon.png

Now next time you get stocked, you have this tool in tool set.

Happy Debugging.