Updating One to many relation in laravel 5.3

前端 未结 1 976
傲寒
傲寒 2021-01-25 02:33

I want to update a one to many relationship. For example I have a model called Product

class Product extends Model
{
    protected $primaryKey         


        
1条回答
  •  清歌不尽
    2021-01-25 03:19

    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]);
    }
    

    0 讨论(0)
提交回复
热议问题