Hi I have simple problem in my project. I want to update data in db. The sku codes sent with ajax. Like this A-1, A-2, A-3
I tried:
$sku2 = $request['sku'];
$sku = explode(',', $sku2);
foreach ($sku as $key => $value){
$content = ProductNew::where('sku', $value)->update(['price' =>
$price]);
}
But it updated only first record (A-1) Where is the problem?
This is full fuction
public function setdiscount(Request $request)
{
$discount = Discount::where('id', $request['id'])->first();
$d_price = $discount['price'];
$d_type = $discount['type'];
$price = 17;
$sku2 = $request['sku'];
$sku = explode(',', $sku2);
foreach ($sku as $key => $value){
ProductNew::whereIn('sku', $sku)->update(['price' => $price]);
}
}