2 years ago

Relationships; nested parents?

Posted 2 years ago by brysonreece

Hi! I'm currently using a few Laravel models with hasMany and hasOne relationships. I was wondering if there was a way to retrieve "nested parents"?

For instance if I have School->Bus->Child model relationships, I know I can call $child->bus->school to find out which School a specific Child belongs to. I am looking for a way to simply call $child->school as our relationships expand to more nested instances in the future.

e.g. State->County->City->School->Bus->Child being the hierarchy, but being able to call $child->city or $child->state and having it return the appropriate model.

Please sign in or create an account to participate in this conversation.