1

我在 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');
}

此图像显示通过表单发布到服务器的数据

预期结果是重定向到带有消息的 url 但得到 MethodNotAllowedHttpException 此路由不支持 POST 方法。支持的方法:GET、HEAD。

4

2 回答 2

1

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

<form method="POST" action="/plantouser">
于 2019-07-23T11:41:12.830 回答
0

它应该是这样的:

<form method="POST" action="{{ url('plantouser') }}">
于 2019-07-23T11:44:44.363 回答