【发布时间】:2018-06-14 07:22:36
【问题描述】:
问题是我想跳过那个编辑页面。它工作正常。但我想在索引视图中编辑我的数据。
我试过了,但我犯了这个错误
{!! Form::model($choice, ['method' => 'PATCH','route' => ['choices.update', $choice->id]]) !!}
<input class="form-control" value="@foreach ($choices as $choice){{ $choice->question_number }}@endforeach" type="number" name="number"></input>
{!! Form::submit('Update Task', ['class' => 'btn btn-primary']) !!}
{!! Form::close() !!}
试图获取非对象的属性(视图:C:\wamp64\www\zainsurgalt\resources\views\choices\index.blade.php)
索引视图
<td><a href="{{ route('choices.edit', $duplicate->topic->id) }}" class="btn btn-default">Edit</a></td>
编辑视图
{!! Form::model($choice, ['method' => 'PATCH','route' => ['choices.update', $choice->id]]) !!}
<input class="form-control" type="number" name="number"></input>
{!! Form::submit('Update Task', ['class' => 'btn btn-primary']) !!}
{!! Form::close() !!}
控制器更新
public function update(Request $request,Choice $choice){
Choice::where('id', $choice->id)->update([
'question_number' => $request->input('number')
]);
return redirect()->route('choices.index');
}
【问题讨论】:
-
当你点击编辑时使用一个模态来代替显示
-
哦,好主意。我忘记了模态。你能举出什么好例子吗?
-
为什么在模态中应用 foreach 值
-
我想你已经在
{{ $choice->question_number }}...中得到了那个question_number ... -
你检查 $choice, $duplicate->topic 是否为空??