简体   繁体   English

Laravel。 RouteCollection.php中的MethodNotAllowedHttpException

[英]Laravel. MethodNotAllowedHttpException in RouteCollection.php

There is a 2 language version on the site, when you turn on Rus the language is added to the URL "/ru" ie it will be http://site/ru , but at the same time, all attempts to send the form end with an error - "MethodNotAllowedHttpException in RouteCollection.php", in the original languages ​​http://site form Normally Are working 该网站上有2种语言版本,当您打开Rus时,该语言将添加到URL“ / ru”中,即它将是http:// site / ru ,但同时,所有尝试发送该表单的尝试用一个错误结束- “MethodNotAllowedHttpException在RouteCollection.php”,在原来语言的http://网站形式常正在

My forms: 我的表格:

<form action="/callback" method="post">



 Route::post('/callback', 'ApiController@callback');

By registering that route, you're explicitly asking for a POST request, any other method is not allowed. 通过注册该路由,您将明确要求POST请求,不允许使用任何其他方法。

If you can't control the incoming request's method, then you should try using Route::get or Route::any (I wouldn't recommend the last one if you're creating an API). 如果您无法控制传入请求的方法,则应尝试使用Route::getRoute::any (如果要创建API,我不建议使用最后一个)。

If you are confused about how routes work, I recommend you to use named routes, so you're always sure you're pointing the form to the right direction: 如果您对路由的工作方式感到困惑,我建议您使用命名的路由,因此您始终可以确保将表单指向正确的方向:

Route::post('/callback', 'ApiController@callback')->name('api.callback');

And then use it for your form in the view just like 然后将其用于视图中的表单,就像

<form method="POST" action="{{ route('api.callback') }}">

Or if you don't want to give it a name, just use the action helper 或者,如果您不想给它起一个名字,只需使用action助手

<form method="POST" action="{{ action('ApiController@callback') }}">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 RouteCollection.php中的MethodNotAllowedHttpException-Laravel - MethodNotAllowedHttpException in RouteCollection.php - laravel RouteCollection.php Laravel中的MethodNotAllowedHttpException - MethodNotAllowedHttpException in RouteCollection.php Laravel Laravel 5中的RouteCollection.php中的MethodNotAllowedHttpException - MethodNotAllowedHttpException in RouteCollection.php in Laravel 5 RouteCollection.php 第 219 行中的 Laravel 5 MethodNotAllowedHttpException - Laravel 5 MethodNotAllowedHttpException in RouteCollection.php line 219 Laravel 5:RouteCollection.php第219行中的MethodNotAllowedHttpException - Laravel 5: MethodNotAllowedHttpException in RouteCollection.php line 219 RouteCollection.php第218行中的Laravel MethodNotAllowedHttpException: - Laravel MethodNotAllowedHttpException in RouteCollection.php line 218: Laravel 5.1中RouteCollection.php中的MethodNotAllowedHttpException - MethodNotAllowedHttpException in RouteCollection.php in laravel 5.1 MethodNotAllowedHttpException在laravel 5中的RouteCollection.php第207行 - MethodNotAllowedHttpException RouteCollection.php line 207 in laravel 5 Laravel-RouteCollection.php第251行中的MethodNotAllowedHttpException - Laravel - MethodNotAllowedHttpException in RouteCollection.php line 251 RouteCollection.php第201行中的Laravel 5 MethodNotAllowedHttpException: - Laravel 5 MethodNotAllowedHttpException in RouteCollection.php line 201:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM