-1

I want to ask about the relationship model laravel

if I have a model table like this

 Model A (one to one with b)
        - Model B (one to many with c,g,h)
            - Model C (one to many with d, e)
                - Model D
                - Model E (one to many with f)
                    - Model F
            - Model G
            - Model H

what the best relationship will be good with this?

for example I can get the data from model F by using id on Model A

AdityaDees
  • 1,022
  • 18
  • 39

1 Answers1

0

try has many deep relation from this package

https://github.com/staudenmeir/eloquent-has-many-deep

In Model A:

public function f()
{
   return $this->hasManyDeep(F::class, [B::class, C::class, E::class]);
}