I need to update my additional filed user_id
in pivot table... I tried like this:
$commet = Comment::find(2);
$commet->likes()->sync([2,'user_id'=>1]);
But my filed is updated with 0
. Any solution for this?
I think your sync array isn't right. Try:
$commet->likes()->sync(array(
1 => array('user_id' => 1),
2 => array('user_id' => 5),
...
));
Ie.
sync(array(
related_id => array('pivot_field' => value),
...
));
来源:https://stackoverflow.com/questions/33052390/how-to-sync-additional-fields-in-pivot-table-laravel-5