Category: Laravel, PHP

When working with Laravel, you will probably use the query builder in order to create and run database queries. Sometimes you want to see the raw SQL output of a query, for example when you are debugging.

The easiest way to get the raw SQL output of this query, is by using the toSql() method: This will result in: It is fast and simple, but as you can see, the bind parameter for amount > 400 is shown as amount > ?.

You can also capture queries by listening for database events in the boot() method of your AppServiceProvider: This will return the query, and the bindings.

If you don't want to get the raw SQL output of a query programmatically, there are quite some tools out there that can do this for you.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners