laravel中updateOrCreate配合联合索引,可以插入但不可更新,报错提示Illegal offset type
laravel 5.5 php7.0.1
model 中设置:
protected $primaryKey = ['order_id','goods_id'];
public $incrementing = false;
controller中执行updateOrCreate
OrderGoods::updateOrCreate([
'order_id' => $order_id,'goods_id' => $v['goodsId']
],[
'Fee' => $v['Fee'],
'Code' => $v['Code'],
]);
插入时正常,更新时报错:Illegal offset type
求问大神这是什么原因
2 条评论
检查下 $v 里面访问的键值是否都设置了
楼主解决了吗 我也是一样的问题 新增的时候正常,更新的时候就会报错 代码和报错信息如下:
protected $table = 'worker'; public $timestamps = false; // 主键 protected $primaryKey = ['userid', 'corpid']; public $incrementing = false; // 可以被批量赋值的属性 protected $fillable = ['userid', 'name', 'avatar', 'open_userid', 'type', 'company_id', 'id6d', 'corpid'];
AuthWorker::updateOrCreate( ['userid' => $workerInfo['userid'], 'corpid' => $corpid], ['name' => $workerInfo['name'], 'avatar' => $workerInfo['avatar'], 'type' => 1] );
Illegal offset type vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:836