Skip to content

Instantly share code, notes, and snippets.

@acip
Created August 31, 2022 08:30
Show Gist options
  • Save acip/f656ee3e53000004df4fc04b8eaffc6b to your computer and use it in GitHub Desktop.
Save acip/f656ee3e53000004df4fc04b8eaffc6b to your computer and use it in GitHub Desktop.
Display executed queries in Laravel blade (counting duplicates)
@php
// requires \DB::enableQueryLog(); to be executed for the query log is available
$queries = array_count_values(array_column(\DB::getQueryLog(), 'query'));
arsort($queries);
echo "\n";
foreach($queries as $query => $count) {
echo sprintf("%s: %s\n", $count > 1 ? "<span style='color:red'>{$count}</span>" : $count, $query);
}
@endphp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment