Stylized line drawing of mark playing the flute

Outputting the SQL of an Eloquent query

Let's say you have a Laravel Eloquent query like this:

$things = Thing::where(DB::raw('LOWER(name)'), 'LIKE', 'foo')->get();

And then let's say you want to see the actual SQL that's being generated behind the scenes.

Laravel's Query Log to the rescue!

DB::enableQueryLog();
$things = Thing::where(DB::raw('LOWER(name)'), 'LIKE', 'foo')->get();
Log::debug(DB::getQueryLog());