Reputation: 41
I have form with multiple rows and I want to save into DB some columns of every row, but when I press submit I get blank page and there is no errors. My form:
{!! 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() !!}
My route:
Route::put('/operatives',[
'as' => 'updateHelper',
'uses' => 'OperativesController@update'
]);
Controller update function:
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');
}
On localhost everything works just fine, but on server it is shows blank page.
I tried to check my php.ini on server - "post_max_size" and "max_input_vars", but it is the same like on localhost.
Does anyone have any idea why? what I am doing wrong?
Upvotes: 1
Views: 142
Reputation: 26460
The reason nothing is displaying is because you're not actually redirect back. You need to call the back()
method on the redirect()
helper (or on the Redirect
model).
In your update()
method, replace
return back()->with('success','Updated');
With
return redirect()->back()->with('success','Updated');
You should also specify that the form handles a PUT
request, which you can do by setting the method
attribute in your form to 'PUT'
instead of 'POST'
.
'method' => 'PUT'
Upvotes: 2