Route::get('posts', '[email protected]');
Route::get('posts/create', '[email protected]');
Route::get('posts/{id}', '[email protected]')->name('posts.show');
Route::get('get-random-post', '[email protected]');
Route::post('posts', '[email protected]');
Route::post('publish', '[email protected]');
Route::post('unpublish', '[email protected]');
Route::post('delete', '[email protected]');
Route::post('restore', '[email protected]');
Route::post('change-rating', '[email protected]');
Route::get('dashboard/posts/{id}/edit', '[email protected]');
Route::put('dashboard/posts/{id}', '[email protected]');
Route::get('dashboard', '[email protected]');
Route::get('dashboard/posts/{id}', '[email protected]')->name('dashboard.show');
Route::get('dashboard/published', '[email protected]');
Route::get('dashboard/deleted', '[email protected]');
方法PostsController
public function edit($id)
{
$post = Post::findOrFail($id);
return view('dashboard.edit', compact('post'));
}
public function update($id, PostRequest $request)
{
$post = Post::findOrFail($id);
$post->update($request->all());
return redirect()->route('dashboard.show', ["id" => $post->id]);
}
,但是當我改變後,點擊提交按鈕,我得到一個錯誤
RouteCollection.php中的MethodNotAllowedHttpException第233行:
有什麼不對?如何解決它?
UPD
從視圖
{!! Form::model($post, ['method'=> 'PATCH', 'action' => ['[email protected]', $post->id], 'id' => 'edit-post']) !!}
和結果開放的形式我得到
<form method="POST" action="http://mytestsite/dashboard/posts?6" accept-charset="UTF-8" id="edit-post"><input name="_method" type="hidden" value="PATCH"><input name="_token" type="hidden" value="aiDh4YNQfLwB20KknKb0R9LpDFNmArhka0X3kIrb">
偏偏這個動作http://mytestsite/dashboard/posts?6
???
您沒有名爲** dashboard.show **的路由** – Sebastian
我給路由添加了名稱,但錯誤保持不變 – Heidel
您使用PUT方法更新您的帖子,因此請確保您有'您的表單中的{{method_field('PUT')}}' – Sebastian