[英]Laravel firstOrNew() function UPDATES existing record but doesn't save new record
[英]firstOrnew doesn't update existing records but inserts new
大家好,我有以下代碼來更新我的表格
$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']
]);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.