I want to update sku and color data .But My function only update of last array data When I do dd($request->all()) in update form
"_token" => "6OmWbWhVTvyw4PXq1mhZbbcopMehx15pEjOJtWNz"
"name" => "Jacket"
"price" => "4000"
"sku" => array:2 [▼
0 => "057HJI"
1 => "0KL780"
]
"colour" => array:2 [▼
0 => "Red"
1 => "White"
]
]
In Product Controller update function.I want to update sku and colour data but when i clicked updated button,the whole data is comming of last array
public function update(Request $request,Purchase $purchase)
{
$purchase->fill($request->all())->update();
foreach($request->sku as $key => $attr)
$purchase->productattribute()->update([
'sku'=>$attr,
'colour'=>$request->colour[$key];
]);
return redirect()->back();
}
This is my Product Model
protected $fillable = ['name','price'];
public function productattribute()
{
return $this->hasMany(ProductAttribute::class,'product_id');
}
question from:
https://stackoverflow.com/questions/65559657/how-to-update-data-that-is-in-array-and-save-in-another-table 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…