Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More levels of Many-to-many #12

Closed
parelius opened this issue Nov 15, 2018 · 2 comments
Closed

More levels of Many-to-many #12

parelius opened this issue Nov 15, 2018 · 2 comments

Comments

@parelius
Copy link

Your extension looks very promising. However I'm not sure how it handles more levels of many-to-many relations.

Example: App\User belongsToMany App\Group belongsToMany App\Album belongsToMany App\Photo.

How would I get photos belonging to a user? I'm wondering how I would use the hasManyDeep() method.

@staudenmeir
Copy link
Owner

It's possible like this:

class User extends Model
{
    use \Staudenmeir\EloquentHasManyDeep\HasRelationships;

    public function photos()
    {
        return $this->hasManyDeep(
            'App\Photo',
            ['group_user', 'App\Group', 'album_group', 'App\Album', 'album_photo']
        );
    }
}

@parelius
Copy link
Author

Works. Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants