staudenmeir / eloquent-has-many-deep

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

HasMany → ManyToMany #73

Closed osqui closed 4 years ago

osqui commented 4 years ago

Is it possible to perform this action?

staudenmeir commented 4 years ago

Yes, take a look at the example: https://github.com/staudenmeir/eloquent-has-many-deep#manytomany--hasmany

osqui commented 4 years ago

Hi Jonas,

Thanks for your quick response.

I have read your packege's documentation, but I can't figure out how to perform this action:

I have a projects table. I have a tasks table, with a project_id column, so I'm using HasMany. I have a task_user table, so I'm using BelongsToMany (task_id, user_id). This table doesn't have a project_id key. I need to get all the users that belong to a project throught the tasks.

Thanks again, and of course thanks for your great package!

El mié., 22 abr. 2020 a las 20:04, Jonas Staudenmeir (< notifications@github.com>) escribió:

Yes, take a look at the example: https://github.com/staudenmeir/eloquent-has-many-deep#manytomany--hasmany

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/staudenmeir/eloquent-has-many-deep/issues/73#issuecomment-617939809, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABNPBFZD7HJU75BMNDLXEETRN4WUNANCNFSM4MOMGR2A .

staudenmeir commented 4 years ago

Use this relationship:

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

    public function users()
    {
        return $this->hasManyDeep(User::class, [Task::class, 'task_user']);
    }
}
osqui commented 4 years ago

It works, thank you so much :)

El mié., 22 abr. 2020 a las 21:06, Jonas Staudenmeir (< notifications@github.com>) escribió:

Use this relationship:

class Project extends Model{ use \Staudenmeir\EloquentHasManyDeep\HasRelationships; public function users() { return $this->hasManyDeep(User::class, [Task::class, 'task_user']); }}

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/staudenmeir/eloquent-has-many-deep/issues/73#issuecomment-617972287, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABNPBFYJSA7JQWR4VFXAVADRN452TANCNFSM4MOMGR2A .