0

I Have a Blade Form that will execute Post Method, this is my blade

@foreach ($dataku as $row => $order)
                <div class="row">
                    <div class="col-md-12">
                        <div class="row">
                            <div class="col-md-12 text-center">
                                    <b>{{ $order->delivery_order_no }}</b>
                                    <input type="hidden" name="order[{{ $row }}][do_id]" value="{{ $order->id }}">
                                    <input type="hidden" name="order[{{ $row }}][so_id]" value="{{ $order->sales_order->id }}">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="table-responsive m-t-40" style="clear:both;">
                                    <table class="table table-hover" style="font-size: 9pt;">
                                        <thead>
                                            <tr><th class="text-center">No</th>
                                                <th class="text-center">SKUID</th>
                                                <th class="text-center">Item Name</th>
                                                <th class="text-center">UOM</th>
                                                <th class="text-center">Qty So</th>
                                                <th class="text-center">Qty Do</th>
                                                <th class="text-center">Qty Confirm</th>
                                                <th class="text-center">Qty Minus</th>
                                                <th class="text-center">Remark Confirm</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            @foreach ($order->delivery_order_details as $do =>$detOrder )
                                            <tr>
                                                <td>{{ $loop->iteration }}</td>
                                                <td>{{ $detOrder->skuid }}</td>
                                                <td>{{ $detOrder->sales_order_detail->item_name }}</td>
                                                <td>{{ $detOrder->uom->name  }}</td>
                                                <td>{{ $detOrder->sales_order_detail->qty }}</td>
                                                <td>{{ $detOrder->qty_do }}</td>
                                                <td>
                                                    <input type="hidden" class="form-control" name="order[{{ $row }}][detail[][{{ $do }}][skuid]]" value="{{  $detOrder->skuid}}">
                                                    <input type="number" class="form-control" name="order[{{ $row }}][detail[][{{ $do }}][qty_do]]" value="{{ $detOrder->qty_do  }}">
                                                </td>
                                                <td>
                                                    <input type="number" min="0" class="form-control" name="order[{{ $row }}][detail[][{{ $do }}][qty_minus]]" value="0">
                                                </td>
                                                <td>
                                                    <input type="text" placeholder="Remark Confirm" class="form-control" name="order[{{ $row }}][detail[][{{ $do }}][remarks]]">
                                                </td>
                                            </tr>
                                            @endforeach
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>     
                @endforeach

I Just want to get the data from the blade as an array ,... and then this is my controller

public function update(Request $request)
    { 
        return $request->all();  
    }

I Get The Data Like This

array

is the return value from my blade $request->all(); correct? looks like something wrong ???

4
  • Nothing wrong here, the orders contains 2 array. The first array also contains 4 array (details). The 2nd array contains 1 array (details). Commented Aug 21, 2020 at 19:04
  • okey,... thanks before, looks like something worng in detail [: specificly in [ is that not wrong Commented Aug 21, 2020 at 19:14
  • 2
    Would be name="order[{{ $row }}][detail][{{ $do }}][qty_minus]" not name="order[{{ $row }}][detail[][{{ $do }}][qty_minus]]" Commented Aug 21, 2020 at 19:22
  • 1
    Yes its Work Perfectly,... Thanks @sta Commented Aug 21, 2020 at 19:32

1 Answer 1

2

@sta provided an answer but I would make it more detailed:

When you build more complex structure (nested) in a html form input, every next key or list has to be surrounded by [].

So if you do just a nested keys it will be something[key1][key2][key3]. And if you do an array and a nested keys it will be something[key1][key2][][key3], where [] means that [key2] will be an array (and every array element will have a key3 key with provided value in input value attribute.

That's why this input name can't work: order[0][detail[][0][skuid]] but this one will work: name="order[0][detail][0][qty_minus]

Sign up to request clarification or add additional context in comments.

2 Comments

but how about <input type="hidden" name="order[{{ $row }}][do_id]" value="{{ $order->id }}"> ? can we change to order[0][do_id] ?
I used [0] because i didin't want to use {{ $row }} in comment :) If you have a loop - you have to use {{ $row }} in this case because if your input name is or has an array, every element of this array must have different key like [0][id],[1][id] , [2][id] etc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.