Laravel Eloquent Query log

Sometimes it can be tricky to narrow down a faulty relationship.

There is a enableQueryLog() which can help you in cases like this

DB::connection()->enableQueryLog();

$discount = $order->discount()->first(); // WTF?! Gives null?
$query = DB::getQueryLog();

// Ah, sorry
dd($query)