【问题标题】:Laravel 5.2 Model sync() except fieldLaravel 5.2 模型同步()除了字段
【发布时间】:2016-11-14 09:51:47
【问题描述】:

所以我将 $user 作为 User 模型的一个实例,当我这样做时 $user->data()->sync($new_data) 字段 address、country 和 postal_code 得到更新。

但是,如果我想更新除国家/地区以外的所有内容,该怎么办?有什么办法可以做 $user->data()->sync($new_data)->except('country')?

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

【问题讨论】:

    标签: laravel model eloquent synchronization


    【解决方案1】:

    您可以将updateExistingPivot 用作:

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

    【讨论】:

      猜你喜欢
      • 2018-03-30
      • 1970-01-01
      • 1970-01-01
      • 2016-11-01
      • 2016-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-12
      相关资源
      最近更新 更多