Laravel Logo

The other day I had an Eloquent query that wasn’t returning what I expected it to. I started looking for a way to determine what was happening “under the hood” so to speak. It turns out it’s very simple.

// Enable query log
DB::enableQueryLog(); 

$users = User::where('email', '=', 'scott@test.com')->get();

// get the results
dd(DB::getQueryLog()); 

This will output something like the following:

array (
  0 => 
  array (
    'query' => 'select * from `users` where `email` = ?',
    'bindings' => 
    array (
      0 => 'scott@test.com',
    ),
    'time' => 2.75,
  ),
)

Can we all agree dd() is the best thing for quick debugging ever?