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

Eiz's avatar
Level 4

How to sync a pivot table with extra columns

Hi, Suppose I have a table called {surveys} and another table called {questions}. I need to assign questions to surveys with BelongsToMany relationship. So I have a pivot table {question_survey}. Normally, I would use the following function to sync the values in the pivot table:

$questions = array(....);
$survey->questions()->sync($questions);

However, what if I have additional/extra column in the pivot table, for example 'weight', how can I use the previous function to save/update the values of that extra column as well?

0 likes
1 reply

Please or to participate in this conversation.