<small id='381X4'></small><noframes id='381X4'>

    1. <tfoot id='381X4'></tfoot>

        <bdo id='381X4'></bdo><ul id='381X4'></ul>

      1. <legend id='381X4'><style id='381X4'><dir id='381X4'><q id='381X4'></q></dir></style></legend>

      2. <i id='381X4'><tr id='381X4'><dt id='381X4'><q id='381X4'><span id='381X4'><b id='381X4'><form id='381X4'><ins id='381X4'></ins><ul id='381X4'></ul><sub id='381X4'></sub></form><legend id='381X4'></legend><bdo id='381X4'><pre id='381X4'><center id='381X4'></center></pre></bdo></b><th id='381X4'></th></span></q></dt></tr></i><div id='381X4'><tfoot id='381X4'></tfoot><dl id='381X4'><fieldset id='381X4'></fieldset></dl></div>
      3. Laravel - 批量分配异常错误

        时间:2023-09-23

        1. <tfoot id='6Lhwt'></tfoot>

              <bdo id='6Lhwt'></bdo><ul id='6Lhwt'></ul>
            • <legend id='6Lhwt'><style id='6Lhwt'><dir id='6Lhwt'><q id='6Lhwt'></q></dir></style></legend>

                  <tbody id='6Lhwt'></tbody>
              1. <small id='6Lhwt'></small><noframes id='6Lhwt'>

                • <i id='6Lhwt'><tr id='6Lhwt'><dt id='6Lhwt'><q id='6Lhwt'><span id='6Lhwt'><b id='6Lhwt'><form id='6Lhwt'><ins id='6Lhwt'></ins><ul id='6Lhwt'></ul><sub id='6Lhwt'></sub></form><legend id='6Lhwt'></legend><bdo id='6Lhwt'><pre id='6Lhwt'><center id='6Lhwt'></center></pre></bdo></b><th id='6Lhwt'></th></span></q></dt></tr></i><div id='6Lhwt'><tfoot id='6Lhwt'></tfoot><dl id='6Lhwt'><fieldset id='6Lhwt'></fieldset></dl></div>
                  本文介绍了Laravel - 批量分配异常错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试将多行保存到一个表中,但是,我遇到了一个质量分配错误.

                  I am trying to save multiple rows to a table, however, I am presented with a Mass Assignment Error.

                  错误是:IlluminateDatabaseEloquentMassAssignmentExceptioncriteria_id

                  $criteria->save();
                  
                      $criteria_id = $criteria->id;
                  
                       foreach(Input::get('bedrooms') as $bedroom){
                          $new_bedroom=array(
                              'criteria_id' => $criteria->id,
                              'bedroom' => $bedroom,
                              );
                          $bedroom = new Bedroom($new_bedroom);
                          $bedroom->save();
                      }
                  

                  我的数据库结构是:

                  所以没有任何不正确的拼写.criteria_id 来自最近保存的标准的变量(参见上面 forloop 的代码).

                  so there isn't any incorrect spelling. The criteria_id comes from the variable from the recently saved criteria (see code above forloop).

                  任何帮助将不胜感激.

                  推荐答案

                  为了能够通过将属性传递给模型的构造函数来设置属性,您需要在 $fillable 阵列.如文档

                  To be able to set properties by passing them to the model's constructor, you need to list all the properties you need in the $fillable array. As mentioned in the Docs

                  class Bedroom extends Eloquent {
                      protected $fillable = array('criteria_id', 'bedroom');
                  }
                  

                  如果需要,您也可以使用 create 方法.它创建了一个新模型并直接保存:

                  Also you can use the create method if you want. It creates a new model and saves it directly:

                  foreach(Input::get('bedrooms') as $bedroom){
                      $new_bedroom=array(
                          'criteria_id' => $criteria->id,
                          'bedroom' => $bedroom,
                          );
                      $bedroom = Bedroom::create($new_bedroom);
                  }
                  

                  这篇关于Laravel - 批量分配异常错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 Laravel Eloquent 中选择某些字段? 下一篇:将数据插入到 Laravel 中的数据透视表

                  相关文章

                  最新文章

                  <tfoot id='iuW4G'></tfoot>

                  <small id='iuW4G'></small><noframes id='iuW4G'>

                • <legend id='iuW4G'><style id='iuW4G'><dir id='iuW4G'><q id='iuW4G'></q></dir></style></legend>
                    • <bdo id='iuW4G'></bdo><ul id='iuW4G'></ul>

                      <i id='iuW4G'><tr id='iuW4G'><dt id='iuW4G'><q id='iuW4G'><span id='iuW4G'><b id='iuW4G'><form id='iuW4G'><ins id='iuW4G'></ins><ul id='iuW4G'></ul><sub id='iuW4G'></sub></form><legend id='iuW4G'></legend><bdo id='iuW4G'><pre id='iuW4G'><center id='iuW4G'></center></pre></bdo></b><th id='iuW4G'></th></span></q></dt></tr></i><div id='iuW4G'><tfoot id='iuW4G'></tfoot><dl id='iuW4G'><fieldset id='iuW4G'></fieldset></dl></div>