Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vtxmg's avatar

How to sync data on pivot table with where clause?

Hello everyone ... I have a pivot table having three main field (page_id, tag_id, feature_id). I have done sync page with tag or tag with page successfully. But now I want to sync page with tag where feature_id = 1. How can I do this???

0 likes
3 replies
phildawson's avatar
Level 26

It feels like it should naturally be this

$page->tags()->wherePivot('feature_id', 1)->sync($tagIds);

But I think you need to select them first.

4 likes

Please or to participate in this conversation.