app->singleton( DecimalMoneyFormatter::class, fn () => new DecimalMoneyFormatter(new ISOCurrencies()) ); $this->app->singleton( Currency::class, fn () => new Currency( // @phpstan-ignore argument.type (Should throw if not provided) Config::string( 'app.currency', 'EUR' ) ) ); $this->app->singleton( \NumberFormatter::class, fn () => new \NumberFormatter( Config::string('app.locale', 'fr_FR'), \NumberFormatter::CURRENCY ) ); $this->app->singleton(IntlMoneyFormatter::class, function () { $numberFormatter = $this->app->make(\NumberFormatter::class); $currency = $this->app->make(Currency::class); $numberFormatter->setTextAttribute( \NumberFormatter::CURRENCY_CODE, $currency->getCode() ); return new IntlMoneyFormatter($numberFormatter, new ISOCurrencies()); }); } /** * Bootstrap any application services. * * @return void */ public function boot() { $this->sharetoView(); } private function sharetoView(): void { Blade::directive('money', function ($expression): string { return "format($expression); ?>"; }); Blade::directive('currency', function ($_): string { return "getCode(); ?>"; }); } }