diff --git a/src/Listeners/FlushLocaleState.php b/src/Listeners/FlushLocaleState.php index bcb8654cb..e9e20bfcc 100644 --- a/src/Listeners/FlushLocaleState.php +++ b/src/Listeners/FlushLocaleState.php @@ -2,6 +2,8 @@ namespace Laravel\Octane\Listeners; +use Carbon\Laravel\ServiceProvider as CarbonServiceProvider; + class FlushLocaleState { /** @@ -18,5 +20,7 @@ public function handle($event): void $translator->setLocale($config->get('app.locale')); $translator->setFallback($config->get('app.fallback_locale')); }); + + (new CarbonServiceProvider($event->app))->updateLocale(); } } diff --git a/tests/LocaleStateTest.php b/tests/LocaleStateTest.php index 064553163..c2971f2ad 100644 --- a/tests/LocaleStateTest.php +++ b/tests/LocaleStateTest.php @@ -2,6 +2,7 @@ namespace Laravel\Octane\Tests; +use Carbon\Carbon; use Illuminate\Foundation\Application; use Illuminate\Http\Request; @@ -29,4 +30,27 @@ public function test_translator_state_is_reset_across_subsequent_requests() $this->assertEquals('en', $client->responses[1]->getContent()); $this->assertEquals('ms', $client->responses[2]->getContent()); } + + public function test_carbon_state_is_reset_across_subsequent_requests() + { + [$app, $worker, $client] = $this->createOctaneContext([ + Request::create('/test-locale', 'GET'), // should be "en" + Request::create('/test-locale?locale=nl', 'GET'), + Request::create('/test-locale', 'GET'), // should be "en", and not "nl"... + ]); + + $app['router']->get('/test-locale', function (Application $app, Request $request) { + if ($request->has('locale')) { + Carbon::setLocale($request->query('locale')); + } + + return now()->getLocale(); + }); + + $worker->run(); + + $this->assertEquals('en', $client->responses[0]->getContent()); + $this->assertEquals('nl', $client->responses[1]->getContent()); + $this->assertEquals('en', $client->responses[2]->getContent()); + } }