【问题标题】:MethodNotAllowedHttpException for Post Method .Get and Head SupportedPost 方法的 MethodNotAllowedHttpException .Get 和 Head 支持
【发布时间】:2019-12-01 10:47:59
【问题描述】:

我在 web.php 中将我的路由定义为 Post 方法。并且 csrf 令牌也添加到 form 中。 Route:list 命令运行良好并显示该发布路线。但是当我提交表单时,它显示此路由不支持 POST 方法。支持的方法:GET、HEAD。

@csrf 添加到表单标签。 php artisan route:list 工作正常,显示已定义的发布路由。

   <form method="POST" method="plantouser">
              @csrf
              <h1>Select Plan</h1>
              <div>
                <select name="plans" class="form-control">
                  @foreach($plan as $plan)
                  <option value="{{$plan->planamount}}">{{$plan->planname}} of {{ $plan->planamount}}</option>
                  @endforeach
                </select>
              </div>
              <div class="clearfix"></div>
              <div class="separator">
                <button type="submit">Submit</button>
              </div>
            </form>

Route::post('/plantouser','PlanController@planToUser');

public function planToUser(Request $request){

    $payment=Planpaymentdetail::create([
            'paymenttype'=>'online',
            'pyamount'=>$price,
            'pycoinamount'=>$dec['result']['amount'],
            'pytxnhash'=>$dec['result']['txn_id'],
            'pyinitiatetime'=>now(),
        ]);
    return redirect()->back()->with('success','Plan selected successfully');
}

this image showing data which is post by form to server

预期结果是重定向到带有消息的 url 但是在获取 MethodNotAllowedHttpException 时,该路由不支持 POST 方法。支持的方法:GET、HEAD。

【问题讨论】:

  • 用完整的表格更新问题。

标签: php laravel routes methodnotfound


【解决方案1】:

您发布到的 URL 应使用表单标签的 action 属性设置,而不是 method 属性:

<form method="POST" action="/plantouser">

【讨论】:

  • 感谢您解决问题。一件小事引起了问题。
【解决方案2】:

应该是这样的:

<form method="POST" action="{{ url('plantouser') }}">

【讨论】:

    猜你喜欢
    • 2020-02-08
    • 2023-02-05
    • 2019-08-28
    • 2019-08-31
    • 2021-05-05
    • 1970-01-01
    • 2020-08-10
    • 2019-12-29
    相关资源
    最近更新 更多