There are routes
Route::get('posts', 'PostsController@index');
Route::get('posts/create', 'PostsController@create');
Route::get('posts/{id}', 'PostsController@show')->name('posts.show');
Route::get('get-random-post', 'PostsController@getRandomPost');
Route::post('posts', 'PostsController@store');
Route::post('publish', 'PostsController@publish');
Route::post('unpublish', 'PostsController@unpublish');
Route::post('delete', 'PostsController@delete');
Route::post('restore', 'PostsController@restore');
Route::post('change-rating', 'PostsController@changeRating');
Route::get('dashboard/posts/{id}/edit', 'PostsController@edit');
Route::put('dashboard/posts/{id}', 'PostsController@update');
Route::get('dashboard', 'DashboardController@index');
Route::get('dashboard/posts/{id}', 'DashboardController@show');
Route::get('dashboard/published', 'DashboardController@published');
Route::get('dashboard/deleted', 'DashboardController@deleted');
methods in 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]);
}
but when I change post and click submit button, I get an error
MethodNotAllowedHttpException in RouteCollection.php line 233:
What's wrong? How to fix it?
via Heidel