vincent15000's avatar

How to retrieve only some pivot values (not all)

Hello,

I have this relationship.


public function articles(): BelongsToMany
{
    return $this->belongsToMany(Article::class, 'group_article')->using(GroupArticle::class)->withPivot('formula', 'rounding_rule', 'precision');
}

public function publicArticles(): BelongsToMany
{
    return $this->belongsToMany(Article::class, 'group_article')->as('articles')->using(GroupArticle::class)->withPivot('rounding_rule', 'precision');
}

I have tried to add publicArticles relationship to retrieve only 2 additionnal pivot datas instead of 3 ones.

I also have tried to add withPivot() in the query inside ->load(), but it doesn't work, I always retrieve the 3 additional pivot datas.

How can I do to retrieve only 2 pivot datas ?

Thanks for your help.

V

0 likes
3 replies
vincent15000's avatar

Yes it's solved. In fact I work with 2 different relationships and it works fine.

Please or to participate in this conversation.