Post 方法 .Get 和 Head 支持的 MethodNotAllowedHttpException

MethodNotAllowedHttpException for Post Method .Get and Head Supported

我在 web.php 中将我的路线定义为 Post 方法。并且在 form 中也添加了 csrf token。 Route:list 命令运行完美并显示 post 路由。但是当我提交表单时,它显示 The POST method is not supported for this route。支持的方法:GET、HEAD。

@csrf 添加到表单标签。 php artisan route:list 工作正常显示定义的 post 路线。

   <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 The POST method is not supported for this route。支持的方法:GET、HEAD。

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

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

应该是这样的:

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