I have a Dynamic Sortable Table where I can add or delete rows like enter image description here
Now I am struggling to insert these data into my database (Mysql).
here is my view page
<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('ProcessName', '', ['id'=>'ProcessName', 'class' => 'form-control', 'placeholder'=>''])}}
</td>
<td data-name="MachineName">
<div class="form-group row-fluid m-auto">
<select name="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('MachineQty', '', ['id'=>'MachineQty', 'class' => 'form-control', 'placeholder'=>''])}}
</td>
<td data-name="SMV">
{{Form::number('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>
there is my controller
// Create Post
$work_breakdown = new work_breakdown;
$work_breakdown->Buyer = $request->input('Buyer');
$work_breakdown->Style = $request->input('Style');
$work_breakdown->Item = $request->input('Item');
$work_breakdown->Size = $request->input('Size');
$work_breakdown->ThreadType = $request['Thread'];
$work_breakdown->Description = $request->input('Description');
$work_breakdown->ProductImage = $fileNameToStore;
$work_breakdown->user_id = auth()->user()->id;
$work_breakdown->save();
$maxValue = work_breakdown::max('id');
$i = 0;
$ProcessName_ID = $request->input('MachineName');
foreach($ProcessName_ID as $key => $MachineName) {
$i++;
// Create Post
$work_breakdown = new work_breakdown;
$work_breakdown->ProductID = $maxValue;
$work_breakdown->MachineID = $MachineName;
$work_breakdown->ProcessName = $request->input('ProcessName');
$work_breakdown->MachineQty = $request['MachineQty'];
$work_breakdown->SMV = $request['SMV'];
$work_breakdown->user_id = auth()->user()->id;
$work_breakdown->save();
}
and I find this error: "Invalid argument supplied for foreach()"