如何解决laravel 5.3中RouteCollection.php中的MethodNotAllowedHttpException?

How to solve MethodNotAllowedHttpException in RouteCollection.php in laravel 5.3?

我的看法是这样的:

{!! Form::open(['route' => ['users.store.year.month', $year, $month]]) !!}                
    @include('users.fields')
{!! Form::close() !!}

我的路线是这样的:

Route::get('users/store/{year}/{month}', 'UserController@store')
        ->name('users.store.year.month');

我的控制器是这样的:

public function store(CreateTunkinRequest $request, $thang, $month)
{
    ...
    return redirect(route('users.proses', ['month' => $month, 'year' => $year]));
}

当我输入数据并保存时,出现了这样的错误:

MethodNotAllowedHttpException in RouteCollection.php line 218:

我该如何解决?

当您默认使用laravel 集合时,将采用POST 方法,因此请将您的表单更改为

{!! Form::open(['route' => ['users.store.year.month', $year, $month] , 'method' => 'get']) !!}

https://laravelcollective.com/docs/5.3/html#opening-a-form

当您在 POST 路由上发出 GET 请求时,您可能会遇到此错误,反之亦然。您正在使用 Route::get,但您的表单的默认方法是 POST。