DEV Community

Cover image for 🔥 Laravel devs — stop using DB::enableQueryLog()
devTalk
devTalk

Posted on

🔥 Laravel devs — stop using DB::enableQueryLog()

I just published a quick but powerful tip that most
Laravel developers overlook completely.

Did you know Laravel has 6 built-in Eloquent query
debugging methods?

Most of us write this the hard way:

DB::enableQueryLog();
$users = User::where('active', 1)->get();
dd(DB::getQueryLog());
Enter fullscreen mode Exit fullscreen mode

When you can just do this:

User::where('active', 1)
    ->orderBy('created_at', 'desc')
    ->ddRawSql();
Enter fullscreen mode Exit fullscreen mode

One line. Full raw SQL. No setup. No package needed.

Here's the full toolkit:

Method What it does
->dd() Dump results and die
->dump() Dump results, continue execution
->ddRawSql() Full raw SQL with bindings, then die
->dumpRawSql() Full raw SQL, continue execution
->toSql() SQL string with ? placeholders
->getBindings() Array of all binding values

I covered all 6 methods with real Artisan Tinker
examples in my latest article.

👉 Read it here

Drop a 🔥 if you didn't know about ->ddRawSql()!

Top comments (0)