0
在我的应用程序中,我通过查看产品来节省客户的兴趣,添加到购物车,订单和类别查看。Laravel更新或创建增值
现在,这里是我的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);
}
这里是我的customerInterest型号
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和兴趣列复合唯一指数。
如果USER_ID,相关列存在
我想更新数据
如果不是我想插入数据。
我使用updateOrCreate方法但无法增加$ data数组中的值。
我该怎么做?