Menu

Post image 1
Post image 2
1 / 2
0

πŸ”₯ Laravel devs β€” stop using DB::enableQueryLog()

DEV CommunityΒ·devTalkΒ·19 days ago
#71VlkBRx
Reading 0:00
15s threshold
Cover image for πŸ”₯ Laravel devs β€” stop using DB::enableQueryLog()

devTalk

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()!

Read More