gpt4 book ai didi

Laravel syncWithoutDetaching 和附加数据

转载 作者:行者123 更新时间:2023-12-04 11:45:34 27 4
gpt4 key购买 nike

我用谷歌搜索我的手指酸痛,我看不到任何人讨论这个,但我怀疑 Laravel syncWithoutDetaching()方法不接受额外数据的任何参数,如 save() , sync()attach()做?

有人知道这个吗?在 API 文档中,该方法具有以下参数:
array syncWithoutDetaching(Collection|Model|array $ids)
我无法将现有数据添加到访客和事件之间的关系中。我需要为客人添加状态以及他们参加的事件,可能参加或拒绝。

最佳答案

sync()syncWithoutDetaching()两者都没有用于附加值的参数,您必须将附加值作为带有 id 的数组传递。


根据docs :

You may also pass additional intermediate table values with the IDs:



$user->roles()->sync([
1 => ['expires' => true],
2,
3
]);

如果你看 here你可以看到 syncWithoutDetaching()只需拨打 sync()但通过 false作为第二个论点。

在你的情况下,它会是这样的:

$event->guests()->syncWithoutDetaching([
1 => ['attending' => true],
2 => ['attending' => false]
])

关于Laravel syncWithoutDetaching 和附加数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54944227/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com