Level 6
Check out the last example in this chapter https://laravel.com/docs/5.2/eloquent-relationships#inserting-many-to-many-relationships
3 likes
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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?
Check out the last example in this chapter https://laravel.com/docs/5.2/eloquent-relationships#inserting-many-to-many-relationships
Please or to participate in this conversation.