Did you enable the query log?
DB::connection()->enableQueryLog();
It's disabled by default now.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi all:
Am trying to debug a weird situation where data is getting deleted unexpectedly, so am trying to get a log of the SQL that Eloquent generates in the course of its business. This forms part of an API layer I'm building for an older application; I've basically built Eloquent models that match the existing database structure and am using that to build out an API layer using the Slim Framework, The PHP League's Fractal and a bunch of other tools (this project was started before Lumen launched...)
So, basically, I'm booting Eloquent using the Capsule manager, basically as follows:
use Illuminate\Database\Capsule\Manager as Capsule;
$db = new Capsule();
$db->addConnection([
'driver' => getenv('DATABASE_DRIVER'),
'host' => getenv('DATABASE_HOST'),
'database' => getenv('DATABASE_SCHEMA'),
'username' => getenv('DATABASE_USERNAME'),
'password' => getenv('DATABASE_PASSWORD'),
'charset' => getenv('DATABASE_CHARSET'),
'collation' => getenv('DATABASE_COLLATION'),
'prefix' => getenv('DATABASE_PREFIX'),
]);
$db->setAsGlobal();
$db->bootEloquent();
What I'm trying to do is get a list of the SQL queries executed by Eloquent as part of a particular API call. I know that DB::getQueryLog() should work inside a Laravel instance. However, I can't seem to get this right. I've tried a couple of things, including (using the $db set above) $db->getConnection()->getQueryLog(), but I seem to be getting a big fat nada.
Any advice appreciated on this, it's driving me nuts...
Did you enable the query log?
DB::connection()->enableQueryLog();
It's disabled by default now.
Please or to participate in this conversation.