Ad

Laravel 5.3 Log Query Result?

- 1 answer

I'm trying to find out which sql queries are slow in a legacy application of my company, so I'm logging the queries as described at https://laravel.com/docs/5.3/database#listening-for-query-events

DB::listen(function ($query) {
    \Log::info($query->sql);
    \Log::info($query->bindings);
    \Log::info($query->time); //in milliseconds
}

And this works fine. However, it would be interesting to log the actual result of the queries too. Is that possible?

I couldn't find what properties this query variable has, is it just those three? Or can I get the actual result of the query too?

This is the first time I work in php, so assume no knowledge. Thanks a lot!

Ad

Answer

You could use the logger helper

https://laravel.com/docs/5.3/helpers#method-logger

logger()

The logger function can be used to write a debug level message to the log:

logger($query->get());

So where ever you build up your query get the data en logger($data);

Ad
source: stackoverflow.com
Ad