Level 8
Try the boot() method in the AppServiceProvider class
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Where should i putDB::enableQueryLog and DB::enableQueryLog` in my app to fetch all query logs ?
You could put a DB::listen in a custom middleware that gets executed on every Request in the application.
// app/Http/Middleware/LogsQueries.php
public function handle(Request $request, Closure $next)
{
DB::listen(function ($query) {
\Log::debug($query->sql);
});
return $next($request);
}
// app/Http/Kernel.php
protected $middleware = [
\App\Http\Middleware\LogsQueries::class,
// ...
Please or to participate in this conversation.