【问题标题】:methodnotallowedhttpexception in routecollection.php line 218routecollection.php 第 218 行中的 methodnotallowedhttpexception
【发布时间】:2017-08-09 03:22:55
【问题描述】:

我知道这是重复的问题。我仍然无法纠正这个问题,所以有人可以帮忙吗?

Routes.php

   Route::post('/form-submit',[
   'uses' => 'UserController@formSubmit',
   'as' => 'f.submit',
]);

用户控制器.php

public function formSubmit() #form-submit
{
   echo"Form Submit Method";
}

test_view.php

@extends('Layout.master')
@section('Content')
 {!! Form::open([
         'route' => 'f.submit', 'method' => 'post'
 ]) !!}
  {!! Form::test('username') !!}
  {!! Form::submit('submit')!!}
 {!! Form::close() !!}
@endsection

如果我对此代码使用 get 方法。然后直接显示Form Submit Method,如果我使用post方法,则显示上述错误

【问题讨论】:

  • 我从来没有使用过 Laravel,所以你可能正在做一些高级的事情。无论如何,根据laravel.com/docs/5.4/routing,我没有发现将数组传递给第二个参数的示例。第二个参数应该是一个回调,因此您需要一个匿名函数或范围内可访问函数的名称。
  • 最好指定您使用的 Laravel 版本...
  • Route::post('/form-submit', 'UserController@formSubmit' ); 我也试过这个,即使是匿名函数。
  • Laravel 5.2 版本
  • 这很令人沮丧。 laravel.com/docs/5.2/routing#named-routes 显示数组使用情况,但 laravel.com/docs/5.4/routing#named-routes 不显示。祝你好运

标签: php forms laravel


【解决方案1】:

我直接得到“表单提交方法”而不是它应该打开 test_view 表单。我有一个使用 POST 或 GET 方法的解决方案。

    Route::post('/form-submit',['
        'uses' => 'UserController@formSubmit'
        'as' => 'f.submit'
  ']});

但是 POST 方法仍然不起作用。

【讨论】:

    【解决方案2】:

    我觉得

     //change '/form-submit' to 'f.submit'
        Route::post('/f.submit',[
           'uses' => 'UserController@formSubmit',
           'as' => 'f.submit',
        ])
    

    并添加 csrf 令牌

    【讨论】:

    • post 方法不起作用,显示上述错误。如果我使用的是 get 方法,那么它会直接向我显示“表单提交方法”。我也试过你的代码,但它是一样的。
    • @Code Demon 你能给我解决办法吗?
    【解决方案3】:

    您需要在表单中随请求传递一个 csrf 令牌。

    【讨论】:

    • 还是一样。
    猜你喜欢
    • 2017-01-03
    • 2016-11-21
    • 2017-01-26
    • 2017-10-12
    • 2017-03-13
    • 2016-11-22
    • 2016-12-26
    • 2016-10-31
    • 1970-01-01
    相关资源
    最近更新 更多