Hello,
I have the following models:
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.
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)
Thank you @tvbeek
I was able to get it working by using:
$memberResult = Member::with('addresses', 'phones', 'emails')->get();
I really appreciate your help!!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community