Skip to content

Instantly share code, notes, and snippets.

View torralbodavid's full-sized avatar
🧙‍♂️

David Torralbo Pérez torralbodavid

🧙‍♂️
View GitHub Profile
@torralbodavid
torralbodavid / gist:8f6103c5f9203f9f6b7b16c15e156075
Created October 16, 2025 09:15
Trace executed SQL queries in Laravel with file, line, and execution time
\Event::listen('Illuminate\Database\Events\QueryExecuted', function ($query) {
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
foreach ($backtrace as $trace) {
if (isset($trace['file']) && !str_contains($trace['file'], base_path('vendor'))) {
dump($trace['file'] . ':' . $trace['line']);
break;
}
}
dump([$query->sql, $query->bindings, $query->time]);