Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

soyiso3875's avatar

Why don't my query eager load?

This is my query

$car = Car::query()
    ->orderby('id', 'desc') )
    ->with('User')

I expect Laravel would eager load the user object here? When I call $car->User->age I get multiple queries.

What is going wrong here?

0 likes
1 reply
bobbybouwmann's avatar
Level 88

Your query looks correct. Do you also add get or first to the query? Right now you don't actually perform the query. Because of that, the data is also not auto-loaded.

1 like

Please or to participate in this conversation.