我有多行表单,我想将每行的某些列保存到数据库中,但是当我按Submit时,我得到了空白页,并且没有错误。 我的表格:
{!! Form::open(['route' => ['updateHelper'], 'method' => 'POST','id'=>'beforeSubmitO']) !!}
<table class="table table-striped operatives" id="checkTableO" dir="rtl">
<thead>
<tr>
<th>XXX</th>
<th>XXX</th>
<th>XXX</th>
<th>XXX</th>
<th>XXX</th>
<th>XXX</th>
<th>XXX</th>
<th>XXX</th>
<th>XXX</th>
<th>XXX</th>
<th>XXX</th>
<th>XXX</th>
<th>XXX</th>
<th>XXX</th>
<th>XXX</th>
<th>XXX</th>
<th>XXX</th>
<th>XXX</th>
<th>XXX</th>
<th>XXX</th>
<th>XXX</th>
</tr>
</thead>
<tbody id="myDIV">
@foreach($operatives as $operative)
<tr>
<td class="selected"><a href="{{route('showHelper',['id'=>$operative->id,'emp_id'=>$operative->employee_no])}}" onclick="myscrollfun()" >
{{$operative->employee_no}}</a>
</td>
<td>{{$operative->employee_name}}</td>
<td>{{$operative->start_date_of_work}}</td>
<td>{{$operative->company}}</td>
<td>{{$operative->termination_reason}}</td>
<td>{{$operative->termination_date}}</td>
<td>{{$operative->position_change}}</td>
<td>{{$operative->position}}</td>
<td dir="ltr">{{$operative->position_percent}}</td>
<td dir="ltr">{{$operative->change_base_salary}}</td>
<td dir="ltr">{{$operative->before_previous_month}}</td>
<td dir="ltr">{{$operative->previous_month}}</td>
<td dir="ltr">{{$operative->current_month}}</td>
<td dir="ltr">{{$operative->gross_difference}}</td>
<td dir="ltr">{{$operative->net}}</td>
<td>{{$operative->risk_level}}</td>
<td><textarea class="comment" id="comment" type="text" name="comment[]" rows="1" cols="23">{{$operative->comment}}</textarea></td>
<td><input {{old('is_proper[]',$operative->isproper)=="V"? 'checked':''}} type="checkbox" class="isproper" name="is_proper[]" value="V" /></td>
<td><input {{old('is_proper[]',$operative->isproper)=="X"? 'checked':''}} type="checkbox" class="isnotproper" name="is_proper[]" value="X" /></td>
<td>
<select class="check" name="rescoring[]">
<option {{old('rescoring[]',$operative->rescoring)=="לא"? 'selected':''}} value="לא" selected>לא</option>
<option {{old('rescoring[]',$operative->rescoring)=="כן"? 'selected':''}} value="כן">כן</option>
</select>
</td>
<td dir="ltr">{{$operative->user_name}}</td>
<td><input type="hidden" name="oper_id[]" value="{{$operative->id}}"></td>
<td><input class="checkboxVal" type="hidden" name="checkbox_val[]" value=''></td>
</tr>
@endforeach
<p class="row justify-content-center pagination">{{$operatives->links()}}</p>
</tbody>
</table>
{{Form::hidden('_method','PUT')}}
{{Form::submit('save',['class'=>'btn btn-primary float-right','id'=>'save', 'onclick'=>'myscrollfun()'])}}
{!! Form::close() !!}
我的路线:
Route::put('/operatives',[
'as' => 'updateHelper',
'uses' => 'OperativesController@update'
]);
控制器更新功能:
public function update(Request $request)
{
$oper_id = $request->oper_id;
$comment = $request->comment;
$rescoring = $request->rescoring;
$checkboxVal = $request->checkbox_val;
foreach($oper_id as $key => $value){
$operative = Operative::find($value);
$operative->comment = $comment[$key];
$operative->rescoring = $rescoring[$key];
if($checkboxVal[$key] == ''){
$operative->isproper = '';
}
else{
$operative->isproper = $checkboxVal[$key];
}
$operative->save();
}
return back()->with('success','Updated');
}
在localhost上一切正常,但在服务器上显示空白页。
我尝试在服务器上检查我的php.ini-“ post_max_size”和“ max_input_vars”,但与本地主机上的一样。
有人知道为什么吗?我在做什么错了?
答案 0 :(得分:2)
什么都不显示的原因是您实际上没有重定向回去。您需要在back()
帮助器(或redirect()
模型)上调用Redirect
方法。
在您的update()
方法中,替换
return back()->with('success','Updated');
使用
return redirect()->back()->with('success','Updated');
您还应该指定表单处理一个PUT
请求,您可以通过将表单中的method
属性设置为'PUT'
而不是'POST'
来完成此请求。 / p>
'method' => 'PUT'