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

ahmedali32's avatar

Query Enhancement

Auction::where('id', $auctionId) ->with(['round','bids','order.entity','order.vehicle.vehicle_make','order.vehicle.vehicle_model','auctionActions']) ->withCount('bids') ->first();

This is my query I would like it to be one single query to the database instead of sending like 9 queries to the database how I can reach that ? thanks in advance

0 likes
3 replies
ahmedali32's avatar

Thanks for replying, It's Easier with eloquent but it hit the database multiple times like 9 times I'm searching for a way to enhance my queries to only send it in one query statement.

MichalOravec's avatar

You can't do it only in one query if you want to use Eloquent relationships as properties. If you have problem with many queries then use Cache for that.

Documentation: https://laravel.com/docs/7.x/cache

And I told you, if you really want to have only one query without relationships as properties do it with joins.

Please or to participate in this conversation.