本文介绍了雄辩的关系同步也会删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在更新模型并同步一个关系时,如果我没有传入所有已经存在的id,那么该关系将被删除?

When updating a model and I sync a relationship, if I don't pass in all the ids that already exist, will that relationship be removed?

推荐答案

您决定: sync 具有默认为 true 的第二个参数,并负责分离:

You decide: sync has 2nd parameter that defaults to true and is responsible for detaching:

$model->relationship()->sync([1,2,3]);

$model->relationship()->sync([4,5,6]); // attached [4,5,6], detached [1,2,3]
$model->relationship()->getRelatedIds(); // [4,5,6]

// but:
$model->relationship()->sync([4,5,6], false); // attached [4,5,6], detached []
$model->relationship()->getRelatedIds(); // [1,2,3,4,5,6]

这篇关于雄辩的关系同步也会删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 21:56