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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners