updateOrCreate()
和 updateOrInsert()
两个方法都是用来保存数据的时候方便操作“ 存在即更新,反之则创建 ”的
updateOrCreate
方法使用的是 Eloquent ORM
操作的数据库(支持自动添加创建和更新时间),updateOrInsert
方法使用的是查询构造器(不可以自动添加创建和更新时间)
updateOrCreate
返回值是\Illuminate\Database\Eloquent\Model
, updateOrInsert
返回的是 bool
。可以看两个方法的源码注释部分的 @return
下面是updateOrCreate
文档说明和源码