简体   繁体   中英

Laravel localization package throws MethodNotAllowedHttpException on POST request

I use this package for localization https://github.com/mcamara/laravel-localization and it works fine in most cases except with one POST request.

When I try to access:

Route::group(
    [
        'prefix'     => LaravelLocalization::setLocale(),
        'middleware' => ['localeSessionRedirect', 'localizationRedirect', 'auth'],
    ],
    function () {
    Route::post('bsSearch', 'BrandSpendingsController@search')->middleware('premium');
}

I get an MethodNotAllowedHttpException ... When I switch it to GET it works fine... However it works for english language. If I switch the url to http://localhost/de/bsSearch , it throws an error.

Route::get('bsSearch', 'BrandSpendingsController@search')->middleware('premium');

I am really not sure why because this one works fine and it is a POST method as well:

Route::post('editUserProfile/{id}', 'UserController@edit');

I use Laravel 5.3.

EDIT

The english url works because I've set 'hideDefaultLocaleInURL' => true, in laravellocalization.php and when it hides the "en" prefix in URL. If i set it to false , it throws an error for English as well.

Here is an answer

  1. it is better to localize only GET routes by puting them to localized group and don't put there another routes
  2. if you need to localize another methods like POST, PUT, PATCH, DELETE, you should localize your url as described here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM