<bdo id='tOsTA'></bdo><ul id='tOsTA'></ul>

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

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

        <tfoot id='tOsTA'></tfoot>

        更新 Laravel 5.3 中的一对多关系

        时间:2023-09-22

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

            <bdo id='kRPZn'></bdo><ul id='kRPZn'></ul>

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

                • <legend id='kRPZn'><style id='kRPZn'><dir id='kRPZn'><q id='kRPZn'></q></dir></style></legend>
                    <tbody id='kRPZn'></tbody>
                • <tfoot id='kRPZn'></tfoot>
                  本文介绍了更新 Laravel 5.3 中的一对多关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想更新一对多关系.例如,我有一个名为 Product

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

                  class Product extends Model
                  {
                      protected $primaryKey = 'product_id';
                      public $timestamps = FALSE;
                  
                      public function Size(){
                          return $this->hasMany('AppSize');
                      }
                  
                  }
                  

                  和一个名为 Size

                  class Size extends Model
                  {
                      public $timestamps = FALSE;
                      protected $fillable = ['product_id','size'];
                  
                      public function Product(){
                          return $this->belongsTo('AppProduct');
                      }
                  

                  这是我的控制器:

                  public function update(Request $request){
                      for($i = 1; $i <= $sizeCounter; $i++){
                          $selectedSize = "size_$i";
                  
                          if($request->$selectedSize){
                              $array = ['size'=> $request->$selectedSize];
                          }
                      }
                  
                      $Size = Size::where('product_id' , $request->id)->update($array);
                  }
                  

                  但是它正在做什么用选定的产品 id 更新所有尺寸记录到最后一个输入者尺寸.我想用选定的不同尺寸而不是最后选择的尺寸更新所有尺寸

                  But what it is doing updating all the records of size with the selectedd product id to the last enterder size. I want to update all the sizes with the slected diffrent sizes not the last selected sizes

                  如何更新特定产品的尺寸.像多对多关系的同步方法一样,有什么方法可以更新记录.

                  How to update the sizes of a particular product. Like many to many relations' sync method is there any way to update the records.

                  推荐答案

                  你在循环中覆盖你的$array.在 for 循环之后,$array 可能是最后一个大小.

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

                  这篇关于更新 Laravel 5.3 中的一对多关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Laravel 4 eloquent 模型链接额外的 where 子句 下一篇:Laravel - 数据透视表上的附加关系

                  相关文章

                  最新文章

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

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

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

                • <tfoot id='LqvD9'></tfoot>