I want to update a one to many relationship. For example I have a model called Product
class Product extends Model
{
protected $primaryKey
You override your $array
in the loop. After the for loop, $array
has possibly the last size.
In general, your query is correct, but it's about the place of execute. It should be like below:
if (isset($request->$selectedSize)) { // or is_int() ?
$Size = Size::where('product_id', $request->id)->update(['size'=> $request->$selectedSize]);
}