Support the ongoing development of Laravel.io →
posted 2 years ago
Eloquent

Hello,

I have the following models:

  • Member
  • Address (belongs to a member)
  • Phone (belongs to a member)
  • Email (belongs to a member)

How can I query a member and get all the addresses, phone numbers, and emails belonging to that member?

Address, phone, and email have a foreign key (member id) which is how I know what belongs to each member.

I've tried to do something like $memberResult = Member::all();

but that only pulls the member and not all the other fields.

Last updated 2 years ago.

syq246 liked this thread

1
moderator Solution

You can use a with to load the relations in your query:

$memberResult = Member::with('addresses', 'phones', 'emails')->all();

(I assume that the relation functions on your member model are named addresses, phones and emails)

jtsimon93, nickopris, syq246 liked this reply

3
Solution selected by @jtsimon93

Thank you @tvbeek

I was able to get it working by using:

$memberResult = Member::with('addresses', 'phones', 'emails')->get();

I really appreciate your help!!

tvbeek, syq246 liked this reply

2

Sign in to participate in this thread!

Eventy

Your banner here too?

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.

© 2025 Laravel.io - All rights reserved.