Php firstOrnew没有';t更新现有记录,但插入新记录
大家好,我有下面的代码来更新我的表Php firstOrnew没有';t更新现有记录,但插入新记录,php,mysql,laravel,Php,Mysql,Laravel,大家好,我有下面的代码来更新我的表 $product = Product::firstOrNew(array( 'id' => $data['product'][$i]['id'], 'title'=>$data['product'][$i]['Title'], 'isActive'=>$data['product'][$i]['IsActive'], 'status'=>$data['product'][$i]['productstatu
$product = Product::firstOrNew(array(
'id' => $data['product'][$i]['id'],
'title'=>$data['product'][$i]['Title'],
'isActive'=>$data['product'][$i]['IsActive'],
'status'=>$data['product'][$i]['productstatus'],
'user_id'=>$userId,
'item_id'=>$itemId,
'store_id'=>$store_id,
'images'=>$images,
'price'=>$price,
'price_2'=>$price2,
'stock'=>$stock,
'description'=>$description,
'country_id'=>$country,
'manufacture'=>$manufacturer,
'width'=>$width,
'height'=>$height,
'depth'=>$depth,
'is_delivery'=>$isDelivery,
'delivery_type'=>$deliveryType,
'seo_title'=>$seoTitle,
'meta_description'=>$metaDescription,
'meta_tags'=>$metaTags,
'articul'=>$sku
));
$product->save();
它会插入新行,但不会更新现有行一次。我做错了什么?您也可以使用更新或创建
$user = User::updateOrCreate(
['id' => $request->id],
['name' => 'xyz']
]);
大家好,欢迎来到SO!请阅读,也请阅读