Level 16
You can try something like
$data = Country::with('manufacturer.model')->get();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
I have 3 tables:
country
manufacturer (country_id as a foreign key)
model (manufacturer_id as a foreign key)
Example of data I want to display is:
USA
- Ford
-- Mustang
-- Focus
-- Fusion
Japan
- Nessan
-- Armada
-- Patrol
- Toyota
-- Camry
-- Yaris
-- Innova
I was able to display countries and manufacturers like this:
$data = Country::with('manufacturer')->get();
But I'm not sure how to get the car model as well with the same query.
Kindly advise. Thanks
You can try something like
$data = Country::with('manufacturer.model')->get();
Please or to participate in this conversation.