Skip to content

Many to many deep #214

Answered by staudenmeir
dpetrovaliev asked this question in Q&A
Oct 23, 2023 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

Hi @dpetrovaliev,
Use this relationship:

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

    public function sportParks()
    {
        return $this->hasManyDeep(SportPark::class, ['field_customer', Field::class], [null, null, 'id'], [null, null, 'sport_park_id']);
    }
}

Try adding ->distinct() to get unique results:

$uniqueSportParks = $customer->sportParks()->distinct()->get();

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@dpetrovaliev
Comment options

Answer selected by dpetrovaliev
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants