I tried to achive this by listening for query events but I don't seem to have any idea of how I got the count. This is only retrieving list of queries as the callback function cannot modified to return a count variable:
DB::listen(function ($query) {
var_dump('<pre>'.$query->sql.</pre>);
});
I need a solution to count each page executed queries by Laravel.
Super old question but when I searched for a way to do this here is where I ended up. Doesn't seem to be a built-in way to get the count but simply doing something like this will get you what you need;
$count = 0;
DB::listen(function ($query) use (&$count) {
$count++;
});
You might want to store the count somewhere more suitable but this will give you and any others coming here from Google the general idea.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With