代码之家  ›  专栏  ›  技术社区  ›  Coffee

Laravel 5.2模型同步(),字段除外

  •  0
  • Coffee  · 技术社区  · 8 年前

    因此,我将$user作为用户模型的实例,并且 $user->data()->sync($new_data) 田野 地址、国家和邮政编码 获取更新。

    但是如果我想更新呢 除了国家以外的一切 ? 有什么方法可以这样做吗 $user->data()->sync($new_data)->except('country') ?

    目前在文档中找不到任何内容。

    1 回复  |  直到 8 年前
        1
  •  1
  •   Amit Gupta    8 年前

    你可以使用 updateExistingPivot 作为:

    $attributes = ['address' => 'some_value', 'postal_code' => 'some_value'];
    $user->data()->updateExistingPivot($data_id, $attributes);