diff --git a/src/Carbon/Laravel/ServiceProvider.php b/src/Carbon/Laravel/ServiceProvider.php index fb9c88b378..79939f8575 100644 --- a/src/Carbon/Laravel/ServiceProvider.php +++ b/src/Carbon/Laravel/ServiceProvider.php @@ -3,9 +3,13 @@ namespace Carbon\Laravel; use Carbon\Carbon; +use Carbon\CarbonImmutable; use Illuminate\Contracts\Events\Dispatcher as DispatcherContract; use Illuminate\Events\Dispatcher; use Illuminate\Events\EventDispatcher; +use Illuminate\Support\Carbon as IlluminateCarbon; +use Illuminate\Support\Facades\Date; +use Throwable; class ServiceProvider extends \Illuminate\Support\ServiceProvider { @@ -30,7 +34,24 @@ public function boot() public function updateLocale() { $app = $this->app && method_exists($this->app, 'getLocale') ? $this->app : app('translator'); - Carbon::setLocale($app->getLocale()); + $locale = $app->getLocale(); + Carbon::setLocale($locale); + CarbonImmutable::setLocale($locale); + + // @codeCoverageIgnoreStart + if (class_exists(IlluminateCarbon::class)) { + IlluminateCarbon::setLocale($locale); + } + + if (class_exists(Date::class)) { + try { + $root = Date::getFacadeRoot(); + $root->setLocale($locale); + } catch (Throwable $e) { + // Non Carbon class in use in Date facade + } + } + // @codeCoverageIgnoreEnd } public function register()