Last active
November 14, 2024 16:41
-
-
Save leMaur/df0a6381d1276326c02af70e07074650 to your computer and use it in GitHub Desktop.
Middleware that extends Mcamara\Laravel-localization package functionalities. Set the locale LC_TIME for Carbon\Carbon to set the correctly datetime for each selected language. See comment for further details.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Middleware; | |
use Closure; | |
use Carbon\Carbon; | |
use Mcamara\LaravelLocalization\Middleware\LaravelLocalizationMiddlewareBase; | |
class LocalizeDatetime extends LaravelLocalizationMiddlewareBase | |
{ | |
/** | |
* Handle an incoming request. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* @return mixed | |
*/ | |
public function handle($request, Closure $next) | |
{ | |
// If the URL of the request is in exceptions. | |
if ($this->shouldIgnore($request)) { | |
return $next($request); | |
} | |
Carbon::setLocale(app('laravellocalization')->getCurrentLocale()); | |
return $next($request); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use it:
This example use mcamara\laravel-localization package.
in your
App\Http\Kernel.php
add this line to the$routeMiddleware
arrayand finally in your
routes\web.php