【发布时间】:2020-09-23 07:14:56
【问题描述】:
我尝试使用编辑路由更新帖子,但是当我发送表单并使用更新功能时,给我一个错误
我的代码是
<form action="/posts{{$posts->id}}" method="POST">
@method('PUT')
@csrf
<label for="">title</label>
<input type="text" name="title" class="form-control" >
<label for="">body</label>
<textarea type="text" name="body" class="form-control">{{$post->body}}</textarea>
<input type="submit" class="btn btn-primary" value="edit">
【问题讨论】:
-
分享你的路线
-
php 工匠路线:列表
-
您需要将路由定义为
Route::put('posts/{id}', ...)以使其响应PUT请求 -
我正在使用相同的更新路线
-
如果你使用资源控制器路由,你应该使用
action="{{ route('posts.update', [ 'post' => $posts->id ])) }}"来确保你得到正确的路由