$model= CustomerTrademarkDiscount::query()->updateOrCreate([
'trademark_id'=>$discount['trademark_id'],
'company_id'=>$company->id
],[
'trademark_id'=>$discount['trademark_id'],
'company_id'=>$company->id,
'discount' => $discount['discount'],
'type' => $discount['type'],
'status' => $discount['status'],
'updated_id'=>auth()->id()
]);//updateOrCreate存在更新,不存在创建
if($model->wasRecentlyCreated){//判断是否是新建
$model->created_id = auth()->id(); //新建的时候插入用户的id
$model->save(); //保存数据
}
Laravel的updateOrCreate(),只有在创建时才做点什么?
最新推荐文章于 2024-06-17 12:04:32 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)