如何在 Laravel Blade 中将多个子行数据与父行一起添加

我一直在尝试通过刀片添加多个数据。在我的边栏选项卡窗体中,我使用克隆,添加行。例如,一个申请具有许多物料。

我的边栏选项卡视图

http://img.mukewang.com/6313118c00010e8010700583.jpg

刀片视图代码


<form autocomplete="off" method="POST" action="{{ route("requisition.store") }}" enctype="multipart/form-data">

        @csrf

        <div class="form-group">

            <label class="required" for="purpose">Purpose</label>

            <input class="form-control" type="text" name="purpose" id="purpose" required>

            <span class="help-block"></span>

        </div>


        <div class="form-group">

            <label class="required" for="requisition_date">Date</label>

            <input class="form-control" type="date" name="requisition_date" id="requisition_date" required>

            <span class="help-block"></span>

        </div>


        <div class="form-group">

            <label class="required" for="requested_by">Released By</label>

            <input class="form-control" type="text" name="requested_by" id="requested_by" required>

            <span class="help-block"></span>

        </div>


        <table class="table table-bordered">

            <thead>

                <tr>

                    <th>Qty</th>    

                    <th>Unit</th>    

                    <th>Description</th>   

                    <th>

                        <a href="#" class="addRow"><i class="fas fa-plus"></i></a>    

                    </th> 

                </tr>

            </thead>

            <tbody>

                <tr>

                    <td>

                        <input type="number" name="rows[0][qty]" class="form-control quantity" required>  

                    </td>    

                    <td>

                        <input type="text" name="rows[0][unit]" class="form-control" required>  

                    </td>    

                    <td>

                        <input type="text" name="rows[0][description]" class="form-control" required>  

                    </td> 

                    <td>


                    </td>   

                </tr> 

            </tbody>    

        </table>

翻过高山走不出你
浏览 103回答 1
1回答

繁华开满天机

我认为最简单的方法是像这样使用您的追加输入和刀片输入...name="qty[]"而不是name="rows[0][qty]"在控制器中循环通过一个将始终添加的字段。例如;for($i = 0; $i < sizeof($request->qty); $i++)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; RequisitionItem::insert([&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'requisition_id' => $requisition->id,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'qty' => $request->qty[$i],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'unit' => $request->unit[$i],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'description' => $request->description[$i]&nbsp; &nbsp; &nbsp; &nbsp; ]);&nbsp; &nbsp; }您也可以按照以下过程操作,&nbsp; for($i = 0; $i < sizeof($request->qty); $i++)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; $items[] = [&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'requisition_id' => $requisition->id,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'qty' => $request->qty[$i],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'unit' => $request->unit[$i],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'description' => $request->description[$i]&nbsp; &nbsp; &nbsp; &nbsp; ];&nbsp; &nbsp; }&nbsp; RequisitionItem::insert($items);
打开App,查看更多内容
随时随地看视频慕课网APP