Jas*_*ick 8 relational-database eloquent laravel-4
更新模型并同步关系时,如果我没有传入已存在的所有ID,是否会删除该关系?
Jar*_*zyk 15
您决定:sync具有默认的第二个参数true并负责分离:
$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]
Run Code Online (Sandbox Code Playgroud)