I have a form with a table example
Name | Review | Rating | Status
This table may have multiple rows and only Status is editable which is a dropdown field
I am able to show all the data, But when I save using code below, I notice that dd is only showing one row. When I save , one row is saved and then an error is displayed. Error:
ErrorException in DashBoardController.php line 432: Creating default object from empty value
where line number 432 is : $approved_reviews->approved= $status1
Below is my code snippet. Please help.
$approve_reviews = Input::except('_token');
foreach ($approve_reviews as $review_id) {
$approved_reviews = dealer_reviews::where('id',$review_id )->first();
$status1 = Input::get('status');
$approved_reviews->approved= $status1;
$approved_reviews->save();
}
I have also tried Input::all(), but dd shows just one row.
My Form Code
@if(isset($pending_reviews))
{!! Form::open(array('action' => array('DashBoardController@ApproveReviews' ), 'class'=>'form','files' => true,'data-toggle' => 'validator' ,'id'=>'edit_form')) !!}
<div class="table-responsive">
<table class="table table-hover table-condensed table-bordered">
<thead>
<tr class="danger">
<td>
<p style="font-weight:500;font-size:1.0em;"> Dealership Name </p>
</td>
<td>
<p style="font-weight:500;"> Review </p>
</td>
<td>
<p style="font-weight:500;"> Rating</p>
</td>
<td>
<p style="font-weight:500;"> Suggestion</p>
</td>
<td>
<p style="font-weight:500;"> Status </p>
</td>
<tr>
</thead>
@foreach($pending_reviews as $p_review)
<tr class="active">
<td>
<p style="font-weight:500;font-size:1.0em;"> {{$p_review-> dealership_name}} </p>
<input type="hidden" value={{$p_review-> id}} name="review_id">
</td>
<td>
<p style="font-weight:500;font-size:1.0em;"> {{$p_review-> review}} </p>
</td>
<td>
<p style="font-weight:500;font-size:1.0em;"> {{$p_review-> rating}} </p>
</td>
<td>
<p style="font-weight:500;font-size:1.0em;"> {{$p_review-> suggestions}} </p>
</td>
<td>
<p style="font-weight:500;font-size:1.0em;">
<select name="status">
<option value="0">Pending</option>
<option value="1">Approve</option>
</select>
</p>
</td>
<tr>
@endforeach
</table>
</div>
<input type='submit' class="btn btn-success" name='Save' value='Submit' />
{!! Form::close() !!}
@else
<h3> No Pending Reviews </h3>
@endif
Aucun commentaire:
Enregistrer un commentaire