Finding out what queries a request actually ran means either a package, a debug bar that changes the page, or the listener that has been in the framework the whole time.
DB::listen(function ($query) {
Log::debug('query', [
'sql' => $query->sql,
'time' => $query->time,
'path' => request()->path(),
]);
});
// or count them, which is the assertion worth having in a test
DB::enableQueryLog();
// ...
count(DB::getQueryLog());
enableQueryLog() keeps every query in memory, so it is fine in a test and a leak in a long-running worker. The listener is the safe one for production, gated behind a flag and a sampling rate. Bindings are separate from the SQL string, which is correct and means the logged query is not runnable as-is — $query->bindings is where the values are.