【发布时间】:2015-10-15 07:48:25
【问题描述】:
在我的应用中,我根据查看产品、添加到购物车、订单和查看类别来保存客户兴趣。
现在这里是我的 customerInterestController
$customerInterest = [
'user_id' => Auth::user()->id,
'interest' => $category_id,
];
$data = [
'cart_interest' => ($column == 'cart') ? 1 : 0,
'order_interest' => ($column == 'order') ? 1 : 0,
'category_interest' => ($column == 'category') ? 1 : 0,
'view_interest' => ($column == 'view') ? 1 : 0,
];
try{
(new CustomerInterest)->insertCustomerInterest($customerInterest, $data);
}catch(Exception $e){
dd($e);
}
这是我的客户兴趣模型
public function insertCustomerInterest($customerInterest = [], $data = []){
return $this->updateOrCreate($customerInterest, $data);
}
插入数据库没有问题。它有效。
My Table
id
user_id
interest
cart_interest
order_interest
category_interest
view_interest
user_id 和 interest 列是复合 唯一索引。
如果user_id,兴趣列存在
我要更新数据
如果不是,我想插入数据。
我使用 updateOrCreate 方法,但无法增加 $data 数组中的值。
我该怎么做?
【问题讨论】: