Support the ongoing development of Laravel.io →
Database Blade Installation
Last updated 7 months ago.
0

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 :)

0

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.

0

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. :)

0

Sign in to participate in this thread!

Full Stack Europe

Your banner here too?

arafatx arafatx Joined 16 Aug 2015

Moderators

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

Your logo here?

Laravel.io

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

© 2022 Laravel.io - All rights reserved.