staudenmeir / eloquent-has-many-deep

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

Team Leader → has many → Agents → many to many → Clients #58

Closed shanerbaner82 closed 4 years ago

shanerbaner82 commented 4 years ago

I think this package will work for my needs, but I am having an issue finding the right syntax.

We have Team Leaders that have many Agents working for them, Agents have many Clients, but Clients can belong to many Agents, not just one.

So how would I: Team Leader → has many → Agents → many to many → Clients with hasManyDeep?

staudenmeir commented 4 years ago

Use this relationship:

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

    public function clients()
    {
        return $this->hasManyDeep(Client::class, [Agent::class, 'agent_client']);
    }
}
shanerbaner82 commented 4 years ago

Worked like a charm! I figured I just had something out of place.

Thanks! And great job on this package!