How to Get the Query Executed in Laravel 5

Better Stack Team
Updated on November 23, 2022

By default, the query log is disabled in Laravel 5:

Don’t worry, you can enable the query log by running the following:

// enable query log

Then you can display the log like this:

// get the query log

Or alternatively, you can register an event listener and listen for logs:

    function ($sql, $bindings, $time) {
        //  $sql - contains the SQL query
Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

We are hiring.

Software is our way of making the world a tiny bit better. We build tools for the makers of tomorrow.

Explore all positions →

Reliability is the
ultimate feature

Delightful observability tools that turn your logs & monitoring into a secret weapon for shipping better software faster.

Explore Better Stack