【发布时间】:2017-08-10 10:56:39
【问题描述】:
我使用这个包进行本地化https://github.com/mcamara/laravel-localization,它在大多数情况下都可以正常工作,除了一个 POST 请求。
当我尝试访问时:
Route::group(
[
'prefix' => LaravelLocalization::setLocale(),
'middleware' => ['localeSessionRedirect', 'localizationRedirect', 'auth'],
],
function () {
Route::post('bsSearch', 'BrandSpendingsController@search')->middleware('premium');
}
我得到一个MethodNotAllowedHttpException ...当我将它切换到GET 时,它工作正常......但是它适用于英语。如果我将 url 切换为http://localhost/de/bsSearch,则会引发错误。
Route::get('bsSearch', 'BrandSpendingsController@search')->middleware('premium');
我真的不知道为什么,因为这个工作正常而且它也是一个POST 方法:
Route::post('editUserProfile/{id}', 'UserController@edit');
我使用 Laravel 5.3。
编辑
英文网址有效,因为我在laravellocalization.php 中设置了'hideDefaultLocaleInURL' => true,,并且它隐藏了网址中的“en”前缀。如果我将它设置为false,它也会抛出英语错误。
【问题讨论】:
-
尽量使用 PUT 方法而不是 POST,不要忘记更改表单中的方法类型
-
不工作 :(.
-
你改变路线了吗?像这样:Route::put('editUserProfile/{id}', 'UserController@edit');
-
是的。并且 editUserProfile 可以作为 POST 请求,但 bsSearch 不能。
-
我在插件 mcamara/laravel-localization 中使用除 GET 之外的任何方法都有同样的问题。使用 GET 一切正常,但使用 POST、PUT、DELETE 它重定向到 GET