首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >以雄辩的口才更新Laravel多张唱片

以雄辩的口才更新Laravel多张唱片
EN

Stack Overflow用户
提问于 2016-09-13 08:04:26
回答 2查看 300关注 0票数 0

我想将多条记录Update到引用表。以下是$request的响应。

代码语言:javascript
复制
array:21 [
  "_method" => "PATCH"
  "_token" => "xXukmVEsMvyeBODIURqFx9Mhk4LviYrV6iLmAuOY"
  "account_type" => "0"
  "name" => "test"
  "model_id" => "2"
  "location" => "USA"
  "serial_no" => "00055555"
  "status" => "Sales"
  "capacity_lower" => ""
  "weight" => "1212.000"
  "category" => "1"
  "attribute" => array:3 [
    1 => array:1 [
      1 => "1"
    ]
    3 => array:2 [
      3 => "5"
      2 => "2"
    ]
    4 => array:5 [
      5 => "11"
      6 => "13"
      4 => "9"
      7 => "23"
      8 => "37"
    ]
  ]
  "crane_manufacture_id" => "1"
  "condition" => "Average"
  "manufacture_year" => "2020"
  "unit_no" => "222222"
  "hours" => "100"
  "video_url" => ""
  "sub_category" => "4"
  "description" => "dsfs"
  "productImages" => array:7 [
    0 => array:3 [
      "id" => "27"
      "descripton" => "89d9a500-a936-4510-9ca5-5952ee9c0bff.jpg"
      "status_id" => "2"
    ]
    1 => array:3 [
      "id" => "28"
      "descripton" => "89d9a500-a936-4510-9ca5-5952ee9c0bff.jpg"
      "status_id" => "2"
    ]
    2 => array:3 [
      "id" => "29"
      "descripton" => "89d9a500-a936-4510-9ca5-5952ee9c0bff.jpg"
      "status_id" => "2"
    ]
    3 => array:3 [
      "id" => "30"
      "descripton" => "89d9a500-a936-4510-9ca5-5952ee9c0bff.jpg"
      "status_id" => "2"
    ]
    4 => array:3 [
      "id" => "31"
      "descripton" => "89d9a500-a936-4510-9ca5-5952ee9c0bff.jpg"
      "status_id" => "2"
    ]
    5 => array:3 [
      "id" => "32"
      "descripton" => "89d9a500-a936-4510-9ca5-5952ee9c0bff.jpg"
      "status_id" => "2"
    ]
    6 => array:3 [
      "id" => "33"
      "descripton" => "89d9a500-a936-4510-9ca5-5952ee9c0bff.jpg"
      "status_id" => "2"
    ]
  ]
]

我有两张桌子,产品和product_images。我给出了一个产品有多个图像的关系。我在两个表中都应用了hasMany关系。

现在,在更新记录时,我将按照下面的代码更新product_images记录。

代码语言:javascript
复制
DB::enableQueryLog();
        $product = Product::find($id);
        //$product->save($request->input());
        $product->productImages()->update(new ProductImage($request->input('productImages')));
        dd(DB::getQueryLog());

但是我遇到了"MassAssignmentException in Model.php 452: 0“的错误。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-09-13 08:19:58

检查您的模型,产品和product_images都具有可填充属性。参考文档

代码语言:javascript
复制
protected $fillable = ['list of columns to be inserted'];
票数 1
EN

Stack Overflow用户

发布于 2016-09-13 08:08:42

检查可填充属性protected $fillable = [];或使用$request protected $guarded = [];中的所有属性

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39465050

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档