From f1c06b827e0ce7a4f2ed59ee3f360a734029bce7 Mon Sep 17 00:00:00 2001 From: Ilya Kolesnikov Date: Tue, 17 Nov 2020 12:24:40 +0300 Subject: [PATCH] #760 - exclude http methods from processing to solve 'POST not working' issue --- README.md | 4 ++++ .../Middleware/LaravelLocalizationMiddlewareBase.php | 3 +++ src/config/config.php | 1 + 3 files changed, 8 insertions(+) diff --git a/README.md b/README.md index 86151f7..b268eef 100644 --- a/README.md +++ b/README.md @@ -501,6 +501,10 @@ will not work. Instead, one has to use ``` + +Another way to solve this is to put http method to config to 'laravellocalization.httpMethodsIgnored' +to prevent of processing this type of requests + ### MethodNotAllowedHttpException If you do not localize your post url and use a redirect middleware, diff --git a/src/Mcamara/LaravelLocalization/Middleware/LaravelLocalizationMiddlewareBase.php b/src/Mcamara/LaravelLocalization/Middleware/LaravelLocalizationMiddlewareBase.php index 2f2a10e..e12f908 100644 --- a/src/Mcamara/LaravelLocalization/Middleware/LaravelLocalizationMiddlewareBase.php +++ b/src/Mcamara/LaravelLocalization/Middleware/LaravelLocalizationMiddlewareBase.php @@ -20,6 +20,9 @@ class LaravelLocalizationMiddlewareBase */ protected function shouldIgnore($request) { + if (in_array($request->method(), config('laravellocalization.httpMethodsIgnored'))) { + return true; + } $this->except = $this->except ?? config('laravellocalization.urlsIgnored', []); foreach ($this->except as $except) { if ($except !== '/') { diff --git a/src/config/config.php b/src/config/config.php index c04a302..32d382f 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -344,4 +344,5 @@ // Defaults to [] 'urlsIgnored' => ['/skipped'], + 'httpMethodsIgnored' => ['POST', 'PUT', 'PATCH', 'DELETE'], ];