我在 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。