From 9319c2d92d4c53eb7da1028c0f2079ce89dbdd44 Mon Sep 17 00:00:00 2001 From: Leonid Nikitin Date: Mon, 10 Jul 2023 21:44:00 +0600 Subject: [PATCH] A new middleware `UserLocale.php` has been added. This middleware sets the language locale based on each user's preference. It operates by checking if the user's preferred language is set during the request cycle and if so, it changes the app's locale accordingly. This feature facilitates personalization by displaying the app in a user's preferred language. Also, registering the middleware in the `Kernel.php` allows it to be used throughout the application --- app/Http/Kernel.php | 1 + app/Http/Middleware/UserLocale.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 app/Http/Middleware/UserLocale.php diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 2173a97..47fa9de 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -63,5 +63,6 @@ class Kernel extends HttpKernel 'signed' => \App\Http\Middleware\ValidateSignature::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequestsWithRedis::class, 'verified' => \App\Http\Middleware\EnsureUserIsVerified::class, + 'user.locale' => \App\Http\Middleware\UserLocale::class, ]; } diff --git a/app/Http/Middleware/UserLocale.php b/app/Http/Middleware/UserLocale.php new file mode 100644 index 0000000..89d7f47 --- /dev/null +++ b/app/Http/Middleware/UserLocale.php @@ -0,0 +1,19 @@ +user() && $request->user()->lang) { + App::setLocale($request->user()->lang->getLocale()); + } + + return $next($request); + } +}