staudenmeir / eloquent-has-many-deep

Laravel Eloquent HasManyThrough relationships with unlimited levels
MIT License
2.67k stars 157 forks source link

How can I do belongs from many deep ? #102

Closed AxelPariss closed 4 years ago

AxelPariss commented 4 years ago

Hi ! Sorry for the dump question I guess 😅 I have this relation : competition→hasMany→category→hasMany→registration

I do this from my Competition model (and it works great) :

    public function registrations(){
        return $this->hasManyDeep('App\Registration', ['App\Category', 'App\Team']);
    }

But I want to access to a competition from a registration, and I do this but I think it's wrong (because I have an error 😂)

    public function competition(){
        return $this->hasManyDeep('App\Competition', ['App\Category', 'App\Team']);
    }

In fact, I don't understand how belongs relationships works, do you have any idea to have this thing working? Thanks !

AxelPariss commented 4 years ago

Ahah it was a very dumb question XD I found this package which works PERFECT! thank you so much for your work 😇

https://github.com/staudenmeir/belongs-to-through