gpt4 book ai didi

php - 如何从 Laravel 中的 HTML 表中获取值

转载 作者:行者123 更新时间:2023-11-30 21:35:30 27 4
gpt4 key购买 nike

我有一个动态排序表,我可以在其中添加或删除像 enter image description here 这样的行我的 Controller 中有一个循环。该循环根据表的列数运行 4 次。但是我的表有固定的列号和行号是可变的。我想根据行号运行这个循环。这是我的 View 页面

{!! Form::open(['action' => 'WorkBreakdownController@store', 'method' => 'POST', 'enctype' => 'multipart/form-data']) !!}
<table class="table table-hover table-sortable" id="tab_logic" name="DataTable">
<thead>
<tr class="text-center">
<td style="width: 40%;">Process Name</td>
<td style="width: 30%;">Machine Name</td>
<td style="width: 10%;">Machine Qty</td>
<td style="width: 10%;">SMV</td>
<td style="width: 10%;">Action</td>
</tr>
</thead>
<tbody>
<tr id='addr0' data-id="0" class="hidden">
<td data-name="ProcessName">
{{Form::text('items[][ProcessName]', '', ['id'=>'ProcessName', 'class' => 'form-control', 'placeholder'=>''])}}
</td>
<td data-name="MachineName">
<div class="form-group row-fluid m-auto">
<select name="items[][MachineName]" class="form-control" id="MachineName" data-live-search="true">
<option value=""></option>
@foreach($machineName as $machineName)
<option value="{{$machineName->id}}">{{$machineName->MachineName}}</option>
@endforeach
</select>
</div>
</td>
<td data-name="MachineQty">
{{Form::number('items[][MachineQty]', '', ['id'=>'MachineQty', 'class' => 'form-control', 'placeholder'=>''])}}
</td>
<td data-name="SMV">
{{Form::number('items[][SMV]', '', ['id'=>'SMV', 'class' => 'form-control', 'placeholder'=>''])}}
</td>
<td data-name="del">
<a name="del0" id="del0" class="btn btn-outline-danger row-remove" value="del0">Delete</a>
{{-- <button name="del0" class='btn btn-outline-danger row-remove'>Delete</button> --}}
</td>
</tr>
</tbody>

<tfoot>
<tr>
<td colspan="5" style="text-align: left;">
<a id="add_row" class="btn float-right btn-lg btn-block btn-outline-secondary">Add Row</a>
</td>
</tr>
<tr>
<td colspan="5" style="text-align: left;">
{{Form::submit('Save', ['class'=>'btn btn-lg btn-outline-primary btn-block', 'name'=>'ProductInsert'])}}
</td>
</tr>
</tfoot>
</table>

还有 Controller

$j=0;
// $ProcessName_ID = $request->input('MachineName');
foreach($request->input('items', []) as $item){
$work_breakdown = new work_breakdown($item);
$work_breakdown->SN = $j;
$work_breakdown->ProcessName = $request->input("ProcessName{$j}");
$work_breakdown->MachineID = $request->input("MachineName{$j}");
$work_breakdown->MachineQty = $request["MachineQty{$j}"];
$work_breakdown->SMV = $request["SMV{$j}"];
$work_breakdown->user_id = auth()->user()->id;
$work_breakdown->save();
$j++;
}

它只迭代了 4 次,不超过 taht。

最佳答案

假设您只存储文本数据而不是图像,并且您的 ajax post 调用是正确的,您只需在 Controller 中执行以下存储功能:

public function store(Request $request) {
// I just call it device model here don't know your model name
$device = Device::create($request->all());

if($device) {
return redirect()->route('device.index')->with('message', 'Success'); // return to device/index.blade.php with success message
}

return redirect()->route('device.index')->with('message', 'error'); // return to device/index.blade.php with error message

}

关于php - 如何从 Laravel 中的 HTML 表中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54055342/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com