Support the ongoing development of →
Database Blade Installation
Last updated 1 year ago.

It will have to get the data anyway. The only other way would be to get your data in the same query using a SQL Join but I think you would have to build that query yourself.

If you have multiple datasets you can reduce the number of queries by taking advantage of Eager Loading - but that will only reduce the number of queries from x to 2 so in your case it wouldn't make a difference :)


Not sure it's better, but something like:

$user = User::with('Address')->find(Auth::user()->id)->get();

I'm not able to test the syntax atm, but something like this should eager load the Address. Thou you're still gonna end up with 2 queries.


Aha.. Thanks guys. Im actually new to laravel. I was having multiple queries at some other pages (without eager loading) and after reading about eager loading this has solved the problem. Thanks for pointing out about eager loading. :)


Sign in to participate in this thread!


Your banner here too?

arafatx arafatx Joined 16 Aug 2015


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.