我目前在CRUD的更新部分遇到一个奇怪的问题。创建,读取和删除项目效果很好,但是由于某种原因,当我尝试更新时,什么也没发生,并且我的应用程序仍停留在同一页面上。
总而言之,这是单击编辑按钮以调用带有项目形式和值的模式的流程。然后,通过单击“保存更改”按钮进行更改并提交表单,没有任何反应。
这是我正在使用的代码
路线
Route::put('/home/testimonials/{testimonial}/update', 'TestimonialController@update');
TestimonialController更新功能
public function update(Request $request, Testimonial $testimonial)
{
dd($request);
}
编辑模式形式
<div class="modal-body">
<div class="container-fluid">
<form action="/home/testimonials/{{$item->id}}/update" method="POST">
@method('PUT')
@csrf
<div class="form-row">
<div class="form-group col-lg-6">
<label for="firstname">Firstname</label>
<input type="text" name="firstname" value="{{$item->firstname}}" class="form-control" aria-describedby="firstname">
<small id="firstname" class="text-muted">Firstname</small>
</div>
<div class="form-group col-lg-6">
<label for="lastname">Lastname</label>
<input type="text" name="lastname" value="{{$item->lastname}}" class="form-control" aria-describedby="lastname">
<small id="lastname" class="text-muted">Lastname</small>
</div>
</div>
<div class="form-group">
<label for="comment">Comment</label>
<textarea name="comment" class="form-control" cols="30" rows="5" aria-describedby="comment">{{$item->comment}}</textarea>
<small id="comment" class="text-muted">Client's comment</small>
</div>
</form>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-custom-one">Save Changes</button>
</div>
我需要帮助弄清楚在提交表单时尝试转储表单值时什么都看不到。
答案 0 :(得分:0)
您是否正在使用模型绑定?如果没有,您可以将update()
方法更改为以下方法并尝试一下吗?
public function update($testimonial, Request $request)
{
dd($request->all());
}
答案 1 :(得分:0)
这并不能说明为什么我的代码最初会失败,但是只需删除模式部分并再次编写,我的代码就可以工作。