如何解决laravel 5.3中RouteCollection.php中的MethodNotAllowedHttpException? [重复]

如何解决laravel 5.3中RouteCollection.php中的MethodNotAllowedHttpException?  [重复]

问题描述:

This question already has an answer here:

My view is like this :

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

My route is like this :

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

My controller is like this :

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

When I input data and save, there exist error like this :

MethodNotAllowedHttpException in RouteCollection.php line 218:

How can I solve it?

</div>

此问题已经存在 这里有一个答案: p>

  • RouteCollection.php第218行中的MethodNotAllowedHttpException:4 3 answers span> li> ul> div>

    我的观点是这样的: p>

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

    我的路线是这样的: p>

      Route :: get  ('users / store / {year} / {month}','UserController @ store')
      - &gt; name('users.store.year.month'); 
      code>  pre> \  n 
     

    我的控制器是这样的: p>

     公共功能商店(CreateTunkinRequest $ request,$ thang,$ month)
     {
     ... 
      return redirect(route('users.proses',['month'=&gt; $ month,'year'=&gt; $ year])); 
    } 
      code>  pre> 
     
      

    当我输入数据并保存时,会出现如下错误: p>

    RouteCollection.php第218行中的MethodNotAllowedHttpException: p> blockquote>

    我该如何解决? p> div>

When you are using laravel collective by default, a POST method will be assumed, so change your form to

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

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

You may get this error, when you are making a GET request on a POST route, or vice versa. You are using Route::get, but your form's default method is POST.