如何同步数据透视表中的其他字段[Laravel 5] [英] How to sync additional fields in pivot table [Laravel 5]
本文介绍了如何同步数据透视表中的其他字段[Laravel 5]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要更新数据透视表中的其他已归档文件user_id
...我尝试这样做:
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]);
但是我的存档已更新为0
.有什么解决办法吗?
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),
...
));
即.
sync(array(
related_id => array('pivot_field' => value),
...
));
这篇关于如何同步数据透视表中的其他字段[Laravel 5]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文