vendredi 6 octobre 2017

Laravel multiple nested checkbox structured in array and sub-array request

I have a checkbox and nested checkbox. Now, when i send request to laravel controller. I want it to be structured as Mother array and sub-array. Now why is this i am having a trouble in making the request to Array and sub-array?.

Here is the output of my request :

"shippings" => array:3 [▼
        0 => "56"
        "products" => array:2 [▼
          0 => "2"
          1 => "1"
          2 => "1"
        ]
        1 => "57"
      ]
    ]

instead of that, i am having a wrong request data. it must be:

"shippings" => array:3 [▼
            0 => "56"
            "products" => array:2 [▼
              0 => "2"
              1 => "1"

            ]
            1 => "57"
            "products" => array:1 [▼
              2 => "1"
          ]
        ]

HERE is my code in view:

<form action="" method="get" id="updateStatus">
  
  <table class="table table-hover" id="tableOrders">                                    
      <thead>                        
          <tr>
            <th width="4%"><input type="checkbox" id="selectAll" /></th>
            <th width="6%">USER ID</th>

            <th width="15%">SHIP DATE</th>

          </tr>
      </thead>                        
      <tbody>
           @foreach($shippings as $data)
          <tr>
              <td><input type="checkbox" name="shippings[]" value="" />&nbsp;</td>                            
              <td><a href="#" data-value="" class="linkedit">  </a></td>

              <td><a href="#" data-value="" class="linkedit">  </a></td>                                                             
          </tr>
          <tr>
              <td></td>
              <td></td>
              <td><p style="font-weight:bold;">Product Name</p></td>
              <td><p style="font-weight:bold;">Price</p></td>
              <td><p style="font-weight:bold;">Ordered Qty</p></td>
              <td><p style="color:red;font-weight: bold;">Available Qty</p></td>
          </tr>                              
            @foreach($data->products as $product)                              
                  <tr>
                    <td></td>
                    <td><input type="checkbox" name="shippings[products][]" value="" />&nbsp;</td>                
                    <td></td>
                    <td></td>                              
                    <td></td>
                    <td><p style="color:red;"> </p></td>                                      
                  </tr>                              
            @endforeach                            
          @endforeach
      </tbody>
  </table>                      
</form>

any suggestions ? I think this came with my problem:

<td><input type="checkbox" name="shippings[products][]" value="" />&nbsp;</td>




Aucun commentaire:

Enregistrer un commentaire