Level 1
Got it.. $query->first() is the evil one here.
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I wonder why this code generates two queries, is it working as intended or something's wrong with it?
\DB::enableQueryLog();
$user = $request->user()->load(['reservations' => function ($query) use ($now, $time) {
$query->where('date', '>', $now);
$query->where('time', '>', $time);
$query->where('cancelled', false);
$query->orderBy('time');
$query->first();
}]);
dd( \DB::getQueryLog() );

Got it.. $query->first() is the evil one here.
Please or to participate in this conversation.