Php Laravel更新如何更新索引中的数据
问题是我想跳过那个编辑页面。它也很好用。但我想在索引视图中编辑我的数据 我尝试了此操作,但出现了此错误Php Laravel更新如何更新索引中的数据,php,laravel,eloquent,Php,Laravel,Eloquent,问题是我想跳过那个编辑页面。它也很好用。但我想在索引视图中编辑我的数据 我尝试了此操作,但出现了此错误 {!! Form::model($choice, ['method' => 'PATCH','route' => ['choices.update', $choice->id]]) !!} <input class="form-control" value="@foreach ($choices as $choice){{ $choice->question_
{!! 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() !!}
获取对象属性时,必须始终检查对象是否存在
@if (!empty($duplicate->topic))
<td><a href="{{ route('choices.edit', $duplicate->topic->id) }}" class="btn btn-default">Edit</a></td>
@endIf
将
$choice
更改为另一个名称,例如$\u choice
,为避免混淆上面使用的$choice
请在单击编辑时使用模式。我忘了莫代尔。你能提供一个很好的例子吗?为什么你在modalI中应用foreach的值,你认为你已经在{{{$choice->question\u number}}
中得到了这个问题的编号……你是否检查了$choice,$duplicate->topic empty??
{!! 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');
}
@if (!empty($duplicate->topic))
<td><a href="{{ route('choices.edit', $duplicate->topic->id) }}" class="btn btn-default">Edit</a></td>
@endIf
@if (!empty($choice))
{!! 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() !!}
@endIf
@foreach ($choices as $choice){{ $choice->question_number }}@endforeach