mardi 6 décembre 2016

Laravel eloquent relation with 4 tables

So basically, I have 4 tables.

Table 1: Fylker (Counties) Table 2: Kommuner (Municipalities) Table 3: Poststed (Postal) Table 4: Postnumre (Zip)

I'm currently using Laravel 5.3 and the databases are setup and seeded. Now, what I'm wondering about, should I use 4 different models for this? Every table has relations to the previous.

What I want is to get a row from Fylker, then use some relation to get the Kommuner associated with the Fylke, and with another relation get all associated Poststeder and another relation to get all the Postnumre.

Something like this is what I want to achieve:

$fylke -> kommuner -> poststeder -> postnumre;

How would I do this?

enter image description here

enter image description here

enter image description here

enter image description here



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire