我有一個表格示例Laravel Input :: all()只讀取一行
名稱|回顧|評分|狀態
此表可有多行,只有狀態爲可編輯的這是一個下拉場
我能夠顯示所有數據,但是當我保存使用下面的代碼,我注意到,DD爲只顯示一個行。保存時,保存一行,然後顯示錯誤。 錯誤:
ErrorException in DashBoardController.php line 432: Creating default object from empty value
其中行號432:$approved_reviews->approved= $status1
下面是我的代碼段。請幫忙。
$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();
}
我也試過Input::all()
,但dd顯示的只是一行。
我的表單代碼
@if(isset($pending_reviews))
{!! Form::open(array('action' => array('[email protected]'), '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
請分享您的HTML代碼。 –
請分享表格代碼 –
不會解決你的問題,但'dealer_reviews :: where'('id',$ review_id) - > first();'可能是'dealer_reviews :: find($ review_id);' – MECU