Reputation: 99
In short, let's say I have several models:
Driver [id, name]
,
Cars [id, car_brand_id, model, driver_id]
, CarBrands [id, name]
.
So in my drivers.index
I want to list all the drivers with their cars, of course stating the car brand name. I have also stated all the needed relations within the models.
If I retrieve it like $drivers = Drivers::with('cars')->get()
, how can I then access the name of its brand in the view?
Upvotes: 1
Views: 134
Reputation: 674
You can go deeper and deeper with relations. Eg.:
$drivers = Drivers::with(['cars.brand'])->get()
Upvotes: 2